New Shopify Certification now available: Liquid Storefronts for Theme Developers

bulkOperationRunMutation productCreate with variants

comgc
Shopify Partner
1 0 0

Hello,

 

I'm trying to use bulk import to create products but Shopify returns an error for each "variants" field saying:

Field 'xxx' doesn't exist on type 'ProductVariantConnection'.

 

Assume the jsonl file was successfully uploaded.

 

This is my Query part:

 

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

This is my Variables part:

 

"mutation": "mutation call($input: ProductInput!) { productCreate(input: $input) {
product { title productType vendor tags options { name } variants { price weight sku options { values } } }
userErrors { message } } }", "stagedUploadPath": "tmp/xxxxx/bulk/xxx-80f2-46ff-a5da-5aadd83/myfile.jsonl"

And this is an example jsonl file:

 

 

{ "input": { "title": "Product Title", "productType": "ANYTYPE", "vendor": "The Vendor", "tags": "dddd, eee,ggg", "options": ["Size", "Color"], "variants": [ { "price": "111", "weight": 1, "sku": "4444444", "options": ["S", "Rainbow"] }, { "price": "222", "weight": 1.3, "sku": "bbb", "options": ["S", "Blue"] }, { "price": "333", "weight": 1.3, "sku": "tttt", "options": ["M", "Pink"] } ] } }

 

 

 

The Response is:

 

{
    "data": {
        "bulkOperationRunMutation": {
            "bulkOperation": null,
            "userErrors": [
                {
                    "message": "Invalid Bulk Mutation Field - Field 'price' doesn't exist on type 'ProductVariantConnection'"
                },
                {
                    "message": "Invalid Bulk Mutation Field - Field 'weight' doesn't exist on type 'ProductVariantConnection'"
                },
                {
                    "message": "Invalid Bulk Mutation Field - Field 'sku' doesn't exist on type 'ProductVariantConnection'"
                },
                {
                    "message": "Invalid Bulk Mutation Field - Field 'options' doesn't exist on type 'ProductVariantConnection'"
                }
            ]
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 10,
            "actualQueryCost": 10,
            "throttleStatus": {
                "maximumAvailable": 1000.0,
                "currentlyAvailable": 990,
                "restoreRate": 50.0
            }
        }
    }
}

 

 

If I don't use the 'variants' part, the BulkOperation runs fine (obviously removing the 'variants' part in jsonl file).

 

What am I missing?

 

Replies 3 (3)
syedusama0786
Shopify Partner
36 2 8

Hey Bro!
Have you done that ?
i need your help I am doing the same thing but i didn't able to upload JSONL file to shopify can i get some example code for it?
Thanks in advance God Bless u

ShopifyDevSup
Shopify Staff
Shopify Staff
1203 190 420

Hi @syedusama0786 👋

 

The variables containing the mutation needs to connect to the variant edges/nodes as shown below:

 

mutation($input: ProductInput!) {
    productCreate(input: $input) { 
        product {
            id
            variants {
                edges {
                    node {
                        id
                    }
                }
            }
        }
    }
}

 

I'd recommend using our codelabs workshop here that contains example code to help streamline the bulk mutation upload process. 

 

Hope that helps!
 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

syedusama0786
Shopify Partner
36 2 8

HEY BRO @ShopifyDevSup !
Thanks, bro for your time. I am very grateful.
I see codelabs workshop I done the same thing but I got an error as I adding a pic.

syedusama0786_0-1674676785975.png

and the code for my bulk Mutation after uploading the JSONL File is:

    const BULK_OPERATION = `mutation {
        bulkOperationRunMutation(
          mutation: "mutation call($input: ProductInput!) { productCreate(input: $input) { product {id title variants(first: 10) {edges {node {id title inventoryQuantity }}}} userErrors { message field } } }",
          stagedUploadPath: "tmp/21759409/bulk/89e620e1-0252-43b0-8f3b-3b7075ba4a23/bulk_op_vars") {
          bulkOperation {
            id
            url
            status
          }
          userErrors {
            message
            field
          }
        }
      }`




    try {
        const resp = await client.query({
            data: {
                query: BULK_OPERATION,
            },
        });
    } catch (error) {
        if (error instanceof GraphqlQueryError) {
            throw new Error(
                `${error.message}\n${JSON.stringify(error.response, null, 2)}`
            );
        } else {
            throw error;
        }
    }
PLEASE GUIDE ME WHAT CAN I DO AND WHAT IS THE ISSUE WITH THIS CODE.