A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I have a list of items that have to be updated daily on prices and inventory quantities, I already know how to do it individually with the code below:
Hi @dfrance 👋
Generally, we recommend using bulk mutations to update large volumes of data asychronously and the Shopify python library supports GraphQL requests for bulk operations.
Alternatively, you can use the `productVariantsBulkUpdate` mutation to update the variant prices in bulk, and `inventoryBulkAdjustQuantityAtLocation` mutation to bulk modify the inventory quantities directly. Below is an example using the python library:
session = shopify.Session(shop_url, api_version, access_token)
shopify.ShopifyResource.activate_session(session)
mutation = """
mutation ($inventoryItemAdjustments: [InventoryAdjustItemInput!]!, $locationId: ID!) {
inventoryBulkAdjustQuantityAtLocation(inventoryItemAdjustments: $inventoryItemAdjustments, locationId: $locationId) {
inventoryLevels {
id
available
}
}
}
"""
inputs = {
"inventoryItemAdjustments": [
{
"inventoryItemId": "gid://shopify/InventoryItem/41900365676662",
"availableDelta": 2
},
{
"inventoryItemId": "gid://shopify/InventoryItem/41900365742198",
"availableDelta": 3
},
{
"inventoryItemId": "gid://shopify/InventoryItem/41900365807734",
"availableDelta": 4
}
],
"locationId": "gid://shopify/Location/61122510966"
}
shopify.GraphQL().execute(
query=mutation,
variables=inputs,
)
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
While this does help, what I want is to set and not adjust values, I found the mutation "inventorySetOnHandQuantities" but this doesn't do bulk updates from what I saw. is there any alternative to that?
I could of course register the present number on stock and do the difference top adjust to the new stock value. The problem is that this method allows for weird behavior since it will have a time window between getting the present stock value and the new stock value
HI
Is there a bulk mutation for updating inventory at a certain location id?
Checking the list the closest one could be productVariantUpdate
but the field