GraphQL Inventory Management

Solved
Highlighted
Shopify Partner
2 0 0

I am trying to update my inventory levels with GraphQL, however when I try to update them I am getting the error "Quantity couldn't be adjusted because the location was deleted" which is odd as I can use update with using the REST API fine.

Below is a snippet of my code, I would like to know where I maybe going wrong with this mutation.

Alan

 

gql = <<-'GRAPHQL'
        mutation($input: InventoryAdjustQuantityInput!) {
          inventoryAdjustQuantity (input: $input) {
            inventoryLevel {
              available
            }
            userErrors {
              field
              message
            }
          }
        }
        GRAPHQL
        variables = { "input": {
                        "inventoryLevelId": "gid:\/\/shopify\/InventoryLevel\/<locationID>?inventory_item_id=#{product.shopify_inventory_item_id}",
                        "availableDelta": product.variant_inventory_qty
                      }
                    }
query = client.parse gql result = client.query(query, variables: variables)
0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 103 124

Hey @r3id ,

 

This is definitely interesting. In order to look into this further, do you think you can provide the value of the "X-Request-ID" header from the Shopify API response? With this value I can go through our platform logs and see why this error was thrown for this store

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Shopify Partner
2 0 0

Hi @hassain 
Im not getting an error with the API, but the GraphQL, below is the error I am getting "Quantity couldn't be adjusted because the location was deleted." which is odd cause the same location can be updated fine using the API.

 

<GraphQL::Client::Response:0x00007f8e5e99cb38 @original_hash={"data"=>{"inventoryAdjustQuantity"=>{"inventoryLevel"=>nil, "userErrors"=>[{"field"=>nil, "message"=>"Quantity couldn't be adjusted because the location was deleted."}]}}, "extensions"=>{"cost"=>{"requestedQueryCost"=>5, "actualQueryCost"=>5, "throttleStatus"=>{"maximumAvailable"=>1000.0, "currentlyAvailable"=>995, "restoreRate"=>50.0}}}}, @data=#< inventoryAdjustQuantity=...>, @errors=#<GraphQL::Client::Errors @messages={} @details={}>, @extensions={"cost"=>{"requestedQueryCost"=>5, "actualQueryCost"=>5, "throttleStatus"=>{"maximumAvailable"=>1000.0, "currentlyAvailable"=>995, "restoreRate"=>50.0}}}>  

 

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 103 124

Hey @r3id ,

 

The error is still coming from Shopify, so you should still be able to get the value of the X-Request-ID header from the API response. If you are unable to get this for whatever reason, feel free to send me your App's name and API Key, as well as the myshopify.com URL of the store experiencing this issue, and the approximate datetime you saw this error in UTC. With this information I should be able to search through our platform logs to see why this error was thrown. Feel free to DM me this information if you are not comfortable with sharing it on this thread

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 103 124

This is an accepted solution.

Hey @r3id ,

 

Thank you for providing all of the information about your app. I was able to go through our platform logs and see exactly why this error was thrown.

 

In your "input" variable, you have 'inventoryLevelId' set to "gid://shopify/InventoryLevel/35146563687?inventory_item_id=33463365140583" - however this is an incorrect value. Specifically, the "35146563687" portion is incorrect here. This "35146563687" value is the Location ID of physical Location that houses the Inventory Level, but it is not meant to be part of the Inventory Level ID.

 

For your use case, the correct value of the 'inventoryLevelId' input should be "gid://shopify/InventoryLevel/68681433191?inventory_item_id=33463365140583". To get the correct Inventory Level IDs that correspond to each Inventory Level inside a Location, use this query:

 

	{
  	location(id: "gid://shopify/Location/35146563687") {
        id
        inventoryLevels(first:100) {
      		pageInfo {
            hasNextPage
            hasPreviousPage
          }
          edges {
            cursor
            node {  
              id
            }
          }
        }
  	}
	}

The reason why you got the error message you got is because your query had the correct Inventory Item ID but had the wrong inventory group ID (e.g. 35146563687 instead of 68681433191). Our platform assumed that the reason why this mismatch occurred must've been if someone deleted that location from their Shopify store.

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

2 Likes