inventorySetQuantities
Requires access scope. Also: The user must have a permission to update an inventory.
Set quantities of specified name using absolute values. This mutation supports compare-and-set functionality to handle
concurrent requests properly. If is not set to true,
the mutation will only update the quantity if the persisted quantity matches the
value.
If the
value does not match the persisted value, the mutation will return an error. In order to opt out
of the
check, the
argument can be set to true.
Only use this mutation if calling on behalf of a system that acts as the source of truth for inventory quantities, otherwise please consider using the inventoryAdjustQuantities mutation.
Opting out of the check can lead to inaccurate inventory quantities if multiple requests are made concurrently.
It is recommended to always include the
value to ensure the accuracy of the inventory quantities and to opt out
of the check using
only when necessary.
Arguments
- Anchor to inputinput•Inventory
Set requiredQuantities Input! The information required to set inventory quantities.
Anchor to InventorySetQuantitiesPayload returnsInventorySetQuantitiesPayload returns
- Anchor to inventoryAdjustmentGroupinventory•
Adjustment Group The group of changes made by the operation.
- Anchor to userErrorsuser•
Errors The list of errors that occurred from executing the mutation.
- Sets the inventory level for an inventory item at a location
- Setting available quantity at a location with compare-and-swap (CAS) enabled
- Setting available quantity at a location without compare-and-swap (CAS) enabled
- inventorySetQuantities reference
Examples
mutation InventorySet($input: InventorySetQuantitiesInput!) {
inventorySetQuantities(input: $input) {
inventoryAdjustmentGroup {
createdAt
reason
referenceDocumentUri
changes {
name
delta
}
}
userErrors {
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation InventorySet($input: InventorySetQuantitiesInput!) { inventorySetQuantities(input: $input) { inventoryAdjustmentGroup { createdAt reason referenceDocumentUri changes { name delta } } userErrors { field message } } }",
"variables": {
"input": {
"name": "available",
"reason": "correction",
"referenceDocumentUri": "logistics://some.warehouse/take/2023-01-23T13:14:15Z",
"quantities": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"locationId": "gid://shopify/Location/124656943",
"quantity": 11,
"compareQuantity": 1
}
]
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation InventorySet($input: InventorySetQuantitiesInput!) {
inventorySetQuantities(input: $input) {
inventoryAdjustmentGroup {
createdAt
reason
referenceDocumentUri
changes {
name
delta
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"input": {
"name": "available",
"reason": "correction",
"referenceDocumentUri": "logistics://some.warehouse/take/2023-01-23T13:14:15Z",
"quantities": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"locationId": "gid://shopify/Location/124656943",
"quantity": 11,
"compareQuantity": 1
}
]
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation InventorySet($input: InventorySetQuantitiesInput!) {
inventorySetQuantities(input: $input) {
inventoryAdjustmentGroup {
createdAt
reason
referenceDocumentUri
changes {
name
delta
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"input": {
"name": "available",
"reason": "correction",
"referenceDocumentUri": "logistics://some.warehouse/take/2023-01-23T13:14:15Z",
"quantities": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"locationId": "gid://shopify/Location/124656943",
"quantity": 11,
"compareQuantity": 1
}
]
}
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation InventorySet($input: InventorySetQuantitiesInput!) {
inventorySetQuantities(input: $input) {
inventoryAdjustmentGroup {
createdAt
reason
referenceDocumentUri
changes {
name
delta
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"input": {
"name": "available",
"reason": "correction",
"referenceDocumentUri": "logistics://some.warehouse/take/2023-01-23T13:14:15Z",
"quantities": [{"inventoryItemId"=>"gid://shopify/InventoryItem/30322695", "locationId"=>"gid://shopify/Location/124656943", "quantity"=>11, "compareQuantity"=>1}]
}
}
response = client.query(query: query, variables: variables)