Set stock quantities
const url = 'https://apibase.ecomweb.app/api/v1/stores/example/inventory/levels/set';const options = { method: 'POST', headers: {'x-api-key': '<x-api-key>', 'Content-Type': 'application/json'}, body: '{"note":"example","idempotency_key":"example","items":[{"variant_id":1,"state":"available","quantity":1,"expected_quantity":1}],"reason":"correction"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://apibase.ecomweb.app/api/v1/stores/example/inventory/levels/set \ --header 'Content-Type: application/json' \ --header 'x-api-key: <x-api-key>' \ --data '{ "note": "example", "idempotency_key": "example", "items": [ { "variant_id": 1, "state": "available", "quantity": 1, "expected_quantity": 1 } ], "reason": "correction" }'Sets available or on_hand to an exact quantity for up to 250 variants in one request, each variant at most once. Give expected_quantity on an item to refuse the write when the stock has changed since you read it; if any item is stale the request answers 409 INVENTORY_QUANTITY_STALE, but the items that were not stale are still written: their levels are in details.applied and the stale items are in details.stale. Do not retry the whole request blindly; retry only the stale items. The change is recorded in each variant’s history with the reason. Sending the same idempotency_key again writes nothing and answers with replayed true.
Required scopes: write:inventory
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”The store’s ref, as returned by GET /stores.
Request Bodyrequired
Section titled “Request Bodyrequired”object
A note recorded with the change in the variants’ history.
Repeating a key makes the request a no-op.
The variants to set, 1 to 250, each at most once.
object
ID of the variant.
Which quantity to set: available, or on_hand for the total held.
The new quantity, never negative.
The quantity the caller last saw.
Why the stock is being set.
Responses
Section titled “Responses”object
The levels that were written, as they are now.
object
What happens when stock runs out: deny stops sales, continue keeps selling.
Variant ID.
ID of the product the variant belongs to.
Product name.
Product image URL, or null.
The variant’s option values joined with /, or null for a product without options.
Stock keeping unit, or null.
ID of the location that holds the stock.
Whether stock is tracked for the variant.
Units that can be sold now.
Units reserved by orders that are not yet fulfilled.
Units set aside as damaged.
Units set aside for quality control.
Units held back as safety stock.
Units set aside for another reason.
Total of damaged, quality control, safety stock and other.
Units physically held: available, committed and unavailable together.
Units expected from open purchase orders.
When the level last changed, as an ISO 8601 timestamp.
Always empty here. A request with a stale item is refused with 409, and the stale items are in the error’s details.
object
The quantity that was being set.
Variant ID.
The quantity the caller expected, from expected_quantity.
The quantity the variant actually holds now.
True when the idempotency_key was used before: nothing was written and applied is empty.
Example
{ "applied": [ { "inventory_policy": "deny" } ], "stale": [ { "state": "available" } ]}The request is malformed or failed validation.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The key is missing, invalid, revoked or expired.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The key may not do this: a missing scope, a readonly key, a publishable key on a Store API route, or a disallowed origin.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The resource does not exist in this store.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The request conflicts with the resource’s current state.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}