Is there a way to adjust variant quantity to a certain value directly using graphql ?

Allonsy
New Member
1 0 0

I am looking at using inventoryBulkAdjustQuantityAtLocation, but inventoryItemAdjustments only provides a availableDelta field to change quantity, so if I want to update inventory to zero, I have to query for the value first, and this waste the limit points that I dont have enough. So can I directly set quantity of a variant to zero with one request?

Replies 2 (2)
syf_
Shopify Staff
Shopify Staff
95 20 19

Hi @Allonsy,

I believe that setting the quantity of a single variant can be achieved with the inventoryActivate mutation. Sample below

 

mutation inventoryActivate($inventoryItemId: ID!, $locationId: ID!) {
  inventoryActivate(inventoryItemId: $inventoryItemId, locationId: $locationId, available: 0) {
    inventoryLevel {
      id
      available
    }
    userErrors {
      field
      message
    }
  }
}

 

Hopefully this helps you achieve what you're looking to do.

Best,
Seth.

syf_ | Developer Support @ 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

alessmar
Shopify Partner
3 0 0

Hi @syf_,

I'm not able to set a specific value using inventoryActivate mutation, because I always get the previous value as available quantity in output (I tried with 2022-01 release):

 

mutation {
	inventoryActivate(
		available: 27
		inventoryItemId: "gid://shopify/InventoryItem/43596988547233"
		locationId: "gid://shopify/Location/63823773857"
	) {
		inventoryLevel {
			available
		}
	}
}

 

and I get:

 

{
	"data": {
		"inventoryActivate": {
			"inventoryLevel": {
				"available": 19
			}
		}
	},
	"extensions": {
		"cost": {
			"requestedQueryCost": 10,
			"actualQueryCost": 10,
			"throttleStatus": {
				"maximumAvailable": 1000.0,
				"currentlyAvailable": 990,
				"restoreRate": 50.0
			}
		}
	}
}

 

I'm only able to change the level using inventoryAdjustQuantity but it's required to pass a delta and it's a bit unconvenient for me, I would prefer to pass a fixed value.

 

Is there any other way to set the expected value?

 

Thanks and regards,

Alessandro