InventorySetOnHandQuantities knowing what failed

I was looking at the best way to update many products with inventory (https://community.shopify.com/topic/2405187)

I started to investigate InventorySetOnHandQuantities (https://shopify.dev/docs/api/admin-graphql/2023-10/mutations/inventorySetOnHandQuantities). I read this post about failures, if one fails they all fail (https://community.shopify.com/post/2231459))

Sometimes I get the error ‘The specified inventory item could not be found.’, when that happens the whole post fails, nothing gets updated. I keep a record of all inventoryItemId values, so failures would be small, but they would happen

When it fails I get

[{u’field’: [u’input’, u’setQuantities’, u’1’, u’inventoryItemId’], u’message’: u’The specified inventory item could not be found.‘, u’code’: u’INVALID_INVENTORY_ITEM’}]

But what I don’t know is what failed, for example the index of the list. If I sent something like the below I want to know what actually failed, any information would useful, for example the inventoryItemId would be perfect. If I knew what failed I would deal with it, for example remove and try again.

Is there a way to know what failed?

Thanks

Grant

Input

[{‘locationId’: ‘gid://shopify/Location/90440630556’, ‘inventoryItemId’: ‘gid://shopify/InventoryItem/49658289193244’, ‘quantity’: 3210}, {‘locationId’: ‘gid://shopify/Location/90440630556’, ‘inventoryItemId’: ‘gid://shopify/InventoryItem/49214207787292’, ‘quantity’: 4022}]

Mutation

mutation inventorySetOnHandQuantities($input: InventorySetOnHandQuantitiesInput!) {
      inventorySetOnHandQuantities(input: $input) {
        userErrors {
          field
          message
          code
        }
        inventoryAdjustmentGroup {
          createdAt
          reason
          changes {
            name
            delta
          }
        }
      }
    }

Hey @GrantDB ,

Thanks for bringing this up. I was just testing on my end here, and the field section of the user errors does help point to which item is returning the error.

“field”: [> “input”,> “setQuantities”,> “1”,> “inventoryItemId”> ],

The “1” in the field is denoting the second item on the list. The first item is 0, etc.

I hope that helps

  • Kyle G.