What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Using productVariantUpdate with bulkOperationRunMutation to update

Solved

Using productVariantUpdate with bulkOperationRunMutation to update

JJasperr
Tourist
5 1 2

Hi i need to update the price and inventory of the variants once a day and i saw a thread saying i can use productvariantupdate with bulk mutation. I created the bulk mutation below. 

 

mutation {
  bulkOperationRunMutation(mutation: "mutation call($input: ProductVariantInput!) {productVariantUpdate(input: $input) {
    productVariant { id price inventoryQuantity  } userErrors { field message }
  }
}", stagedUploadPath: "tmp/58782580893/bulk/0de283d9-3181-4bd8-9a46-******863adb/shopify_uploads") {
    bulkOperation {
      createdAt
      completedAt
      errorCode
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}

 


I uploaded these variable to the server

 

{"input":{"id": "gid://shopify/ProductVariant/40678598934685", "price": 55.9, "inventoryQuantity": 23.0}}
{"input":{"id": "gid://shopify/ProductVariant/40678600245405", "price": 69.9, "inventoryQuantity": 15.0}}

 

When i run the mutation i get the error that inventoryQuantity field does not exist

 

{"data":{"bulkOperationRunMutation":{"bulkOperation":null,"userErrors":[{"field":null,"message":"Invalid Bulk Mutation Field - Variable $input of type ProductVariantInput! was provided invalid value for inventoryQuantity (Field is not defined on ProductVariantInput)"}]}},"extensions":{"cost":{"requestedQueryCost":10,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":1000.0,"currentlyAvailable":990,"restoreRate":50.0}}}}

 

I want/very much prefer to update the price and inventory in a single mutation. Any help is appreciated thank you.

 

Accepted Solution (1)

Luke_K
Shopify Staff
402 66 102

This is an accepted solution.

Hey @JJasperr 

Yes, that's right - productVariantUpdate is available to be run as part of a bulkOperationRunMutation.  InventoryQuantity does not exist on the productVariantInput, although InventoryQuantities does.

However unfortunately, Inventory Quantities is a create only field(docs)  and so it wouldn't work with productVariantUpdate as part of the bulk mutation.

To update the inventory quantities, after creation, it is looking like you would need to use inventoryBulkAdjustQuantityAtLocation mutation - there are some docs here. Hope that helps!

 

 

 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!

View solution in original post

Reply 1 (1)

Luke_K
Shopify Staff
402 66 102

This is an accepted solution.

Hey @JJasperr 

Yes, that's right - productVariantUpdate is available to be run as part of a bulkOperationRunMutation.  InventoryQuantity does not exist on the productVariantInput, although InventoryQuantities does.

However unfortunately, Inventory Quantities is a create only field(docs)  and so it wouldn't work with productVariantUpdate as part of the bulk mutation.

To update the inventory quantities, after creation, it is looking like you would need to use inventoryBulkAdjustQuantityAtLocation mutation - there are some docs here. Hope that helps!

 

 

 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!