Meaning of SET_ON_HAND_QUANTITIES_FAILED error?

BarnabyWinters
Shopify Partner
2 0 0

I have been using the graphQl inventorySetOnHandQuantities mutation to update stock and recently some of my batches have been failing because individual items return the SET_ON_HAND_QUANTITIES_FAILED error:

 

     "{
           field: null,
           message: "The on-hand quantities couldn't be set. Try again."
      }"

 

Why am I getting this error? What does it mean? What can I do to solve this problem?

 

 

Replies 6 (6)

Liam
Shopify Staff
2731 290 743

Hi Barnaby,

 

What's the full mutation request you're trying to make?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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

kcamel
Shopify Partner
2 0 1

Hey @Liam, I'm getting the same error with the following query:

 

 

 

mutation inventorySetOnHandQuantities($input: InventorySetOnHandQuantitiesInput!) {
  inventorySetOnHandQuantities(input: $input) {
    userErrors {
      field
      message
    }
  }
}
{
  "input": {
    "reason": "correction",
    "setQuantities": [
      {
        "inventoryItemId": "gid://shopify/InventoryItem/42431172739133", 
        "locationId": "gid://shopify/Location/64617152573", 
        "quantity": 0
      },
      # 249 more times for different locations but with the same inventory item id
    ]
  }
}

 

 

Liam
Shopify Staff
2731 290 743

Hi Kcamel 

 

Just to confirm - do you have the write_inventory access scope, as well as the permission to update an inventory? Also which API version are you using?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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

kcamel
Shopify Partner
2 0 1

Thanks for the quick reply @Liam.

 

Yes indeed I do have the `write_inventory` (how do you add inline code?) scope and is running successfully for other Inventory Items.

 

I manged to resolve this on my end. It turns out that of the 250 locations (all at for the same inventory item) I was trying to set one of them was not activated yet. I was able to find out which one it was by trying to up date them one at a time and then finally activating it using the `inventoryActivate` mutation.

 

It would be nice if the `inventorySetOnHandQuantities` mutation offered more details as to why to why the mutation failed. Ideally it would specifically let you know that the inventory could not be set because the location is not active. Instead of just the generic abstract message "The on-hand quantities couldn't be set. Try again.".


Thanks for your help Liam.

 

I hope this might be helpful to someone else.

Liam
Shopify Staff
2731 290 743

Hi again Kcamel - glad you figured this out and thanks for coming back to post your solution.

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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

BarnabyWinters
Shopify Partner
2 0 0

Hi @Liam,

 

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

 
input: {
reason: 'correction',
setQuantities: [
{
inventoryItemId: 'gid://shopify/InventoryItem/48911113421144',
locationId: 'gid://shopify/Location/82770854232',
quantity: 0
},
{
inventoryItemId: 'gid://shopify/InventoryItem/48911113453912',
locationId: 'gid://shopify/Location/82770854232',
quantity: 0
}
# etc. for like 15 other items 
]
}
 
The query works for other items on the shop and fails for this one because of a single inventory item. It also used to work for this item and stopped working 2-3 months ago.
 
Thanks for your help and let me know if you need any other info