Solved

Product csv import not generating variants as mentioned in csv sheet

Dipen_M
Shopify Partner
6 2 0

I am using bulk operation for importing CSV and creating products using Graphql
Now as suggested in "New Product Model" /variants endpoint is deprecated now 
I want to make variants out of the option I have given in CSV 

Screenshot from 2024-05-22 10-56-01.png

Now this is my bulk operation query :

<<<'QUERY'
            mutation ($bulkMutationKeyUpdate:String!) {
                bulkOperationRunMutation(
                    mutation: "mutation call($input: ProductInput!) { productCreate(input: $input) { product {id title handle options {
                        id
                        name
                        position
                        optionValues {
                          id
                          name
                          hasVariants
                        }
                      }variants(first: 250) {
                        edges {
                          node {
                            id
                            title
                            price
                            sku
                          }
                        }
                      }} userErrors { message field } } }"
                    stagedUploadPath: $bulkMutationKeyUpdate
                ) {
                    bulkOperation {
                        id
                        url
                        status
                    }
                    userErrors {
                        message
                        field
                    }
                }
            }
        QUERY;


But it will only generate 1 variant out of the given option 
I want to make variants as i have given in CSV

Shopify App Developer | Sharing Expert Insights
Accepted Solution (1)

Dipen_M
Shopify Partner
6 2 0

This is an accepted solution.

After doing much R&D I found that we can achieve the same with ProductSet Mutation, we need to include graphql query of ProductSet Mutation to our BulkOperation query and assign inputs according to ProductSetInput

here is an example query for reference:

This is a bulkOperation query:

mutation bulkOperationRunMutation(
                    $mutation: String!
                    $bulkMutationKeyUpdate: String!
                ) {
                    bulkOperationRunMutation(
                        mutation: $mutation
                        stagedUploadPath: $bulkMutationKeyUpdate
                    ) {
                        bulkOperation {
                            id
                            url
                            status
                        }
                        userErrors {
                            message
                            field
                        }
                    }
                }


and this is the ProductSet Mutation query that we are passing to our bulkOperation

mutation productSet($productSet: ProductSetInput!, $synchronous: Boolean!) {
                    productSet(synchronous: $synchronous, input: $productSet) {
                            product {
                                id
                                title
                                handle
                                variants(first: 10) {
                                    nodes {
                                        sku
                                        createdAt
                                        updatedAt
                                    }
                                }
                            }
                            userErrors {
                                code
                                field
                                message
                            }
                        }
                    }



Here if you want to know more information you can refer to this document
https://shopify.dev/docs/api/admin/migrate/new-product-model/sync-data#create-a-product-with-variant... 

Shopify App Developer | Sharing Expert Insights

View solution in original post

Reply 1 (1)

Dipen_M
Shopify Partner
6 2 0

This is an accepted solution.

After doing much R&D I found that we can achieve the same with ProductSet Mutation, we need to include graphql query of ProductSet Mutation to our BulkOperation query and assign inputs according to ProductSetInput

here is an example query for reference:

This is a bulkOperation query:

mutation bulkOperationRunMutation(
                    $mutation: String!
                    $bulkMutationKeyUpdate: String!
                ) {
                    bulkOperationRunMutation(
                        mutation: $mutation
                        stagedUploadPath: $bulkMutationKeyUpdate
                    ) {
                        bulkOperation {
                            id
                            url
                            status
                        }
                        userErrors {
                            message
                            field
                        }
                    }
                }


and this is the ProductSet Mutation query that we are passing to our bulkOperation

mutation productSet($productSet: ProductSetInput!, $synchronous: Boolean!) {
                    productSet(synchronous: $synchronous, input: $productSet) {
                            product {
                                id
                                title
                                handle
                                variants(first: 10) {
                                    nodes {
                                        sku
                                        createdAt
                                        updatedAt
                                    }
                                }
                            }
                            userErrors {
                                code
                                field
                                message
                            }
                        }
                    }



Here if you want to know more information you can refer to this document
https://shopify.dev/docs/api/admin/migrate/new-product-model/sync-data#create-a-product-with-variant... 

Shopify App Developer | Sharing Expert Insights