Re: inventorySetOnHandQuantities provides strange results

Solved

inventorySetOnHandQuantities provides strange results

newbie_01
Shopify Partner
34 0 13

I was looking for a way to update inventory in bulk, and tried inventorySetOnHandQuantities.

The update happens, but the returned results have 2 strange behaviours:

  • Each item is listed twice
  • The quantityAfterChange field always returns null

Is this expected? Or am I doing something wrong?

Thanks

----------------------------

QUERY

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

VARIABLES

{  "input": {    "reason": "correction",
	"setQuantities": [
	  {"inventoryItemId": "gid://shopify/InventoryItem/XXX",        
      "locationId": "gid://shopify/Location/XXX",        
      "quantity": 10      }
	]  }}

RESULT

{
    "data": {
        "inventorySetOnHandQuantities": {
            "userErrors": [],
            "inventoryAdjustmentGroup": {
                "createdAt": "2023-05-06T02:49:32Z",
                "reason": "correction",
                "changes": [
                    {
                        "name": "available",
                        "delta": -2,
                        "quantityAfterChange": null
                    },
                    {
                        "name": "on_hand",
                        "delta": -2,
                        "quantityAfterChange": null
                    }
                ]
            }
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 11,
            "actualQueryCost": 11,
            "throttleStatus": {
                "maximumAvailable": 1000.0,
                "currentlyAvailable": 989,
                "restoreRate": 50.0
            }
        }
    }
}

 

 

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1453 238 508

This is an accepted solution.

Hi @newbie_01,

 

Thanks for your post. The two listings coming back in the return result are for the different inventory states that were adjusted by the change ('available' and 'on_hand'), there's a great reference about the inventory state labels here: [Shopify Docs: Inventory State Chart]

 

About quantityAfterChange returning null, that doesn't seem like the expected result and we have been able to replicate so a report has been filed for further investigation.

 

Thanks and hope you have a great day,

Jon551

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

View solution in original post

Replies 2 (2)

ShopifyDevSup
Shopify Staff
1453 238 508

This is an accepted solution.

Hi @newbie_01,

 

Thanks for your post. The two listings coming back in the return result are for the different inventory states that were adjusted by the change ('available' and 'on_hand'), there's a great reference about the inventory state labels here: [Shopify Docs: Inventory State Chart]

 

About quantityAfterChange returning null, that doesn't seem like the expected result and we have been able to replicate so a report has been filed for further investigation.

 

Thanks and hope you have a great day,

Jon551

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

ShopifyDevSup
Shopify Staff
1453 238 508

Hi @newbie_01,

 

The results of the investigation into quantityAfterChange returning null have found that this is expected behaviour when the request is initially submitted as it can take some time to process the inventory moves. 

 

This is described in a bit more detail as comments in the example return values found [in the 'Manage Inventory Quantities and States' dev doc] like this:

 

This field always returns `null` immediately after running the mutation. The value of this field is available only after all written adjustments and moves have been processed.

We're looking into getting this additional note added to the docs for [the inventorySetOnHandQuantities mutation] to make it more visible.

 

If you want to get the quantityAfterChange values later they can be queried on the InventoryAdjustmentGroup object like this, just remember to request the id for the inventoryAdjustmentGroup when performing inventorySetOnHandQuantities as it's not in the example in the docs:

 

{
  node(id: "gid://shopify/InventoryAdjustmentGroup/1234567890") {
    ...on InventoryAdjustmentGroup {
      changes {
        quantityAfterChange
      }
    }
  }
}

 

Hope you have a great day,

Jon551

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