The store API: update a product's or a size's stock from your system
The reference for the stock address of the ArabyBot store API: quantity or difference, products with sizes, the response, and the refusals.
On this page 7
The short answer
With a POST request to the stock address under the product id, with a key that has write access. You send either the new quantity in the stock field, or the difference up or down in the delta field. A product with sizes needs the size's id, because the product's own stock is the sum of its sizes. The change is written in the product's stock history as «via API».
Also asked as: «احدث مخزون المتجر من السيستم بتاعي» · «مزامنة المخزون api» · «update product stock via api» · «sync inventory with store api»
The address and authentication
POST https://app.arabybot.com/store_api/v1/products/{id}/stock Send the store key in the header Authorization: Bearer abst_… or X-Api-Key. This address changes data, so it needs a key with write access; a read key is refused with status 403. You create the key in the store settings.
The fields
stock(optional) The new quantity as it is. Send this field ordelta.delta(optional) The difference: a positive number to add, a negative one to take away.variant_id(optional) The variant id. Required for a product that has sizes.
An example request
cURL
curl -X POST https://app.arabybot.com/store_api/v1/products/88/stock \
-H "Authorization: Bearer abst_YOUR_WRITE_KEY" \
-H "Content-Type: application/json" \
-d '{ "variant_id": 301, "stock": 14 }' PHP
$ch = curl_init('https://app.arabybot.com/store_api/v1/products/88/stock');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer abst_YOUR_WRITE_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'variant_id' => 301,
'stock' => 14,
]),
]);
$answer = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch); Python
import requests
r = requests.post(
'https://app.arabybot.com/store_api/v1/products/88/stock',
headers={
"Authorization": "Bearer abst_YOUR_WRITE_KEY",
},
json={
"variant_id": 301,
"stock": 14,
},
timeout=30,
)
print(r.status_code, r.json()) Node.js
// Node.js 18+
const r = await fetch('https://app.arabybot.com/store_api/v1/products/88/stock', {
method: 'POST',
headers: {"Authorization": "Bearer abst_YOUR_WRITE_KEY", "Content-Type": "application/json"},
body: JSON.stringify({
"variant_id": 301,
"stock": 14
}),
});
console.log(r.status, await r.json());
The response
200
{ "ok": true, "product_id": 88, "variant_id": 301, "stock": 14 } stockin the response is the quantity after the change.- If both
deltaandstockare sent,deltais taken.
The refusals
Every refusal comes back as JSON with "ok": false and the code in error:
- 403
read_only_key: The key can read only; create a key with write access in the store settings. - 422
stock_required: Neitherstocknordeltawas sent. - 422
bad_stock: The difference is larger than a million units. - 409
variant_required: The product has sizes; sendvariant_id. - 404
not_found: No product with this id in the store, or the variant is not one of its own. - 401
unauthorized: The key is missing, wrong or revoked. - 402
store_plan_closed: The store plan has ended; renew it. - 429: More than 120 requests in a minute.
- 500
server_error: A failure on our side; try again.
The limits
120 requests a minute from one IP address; passing that returns status 429. A store can have up to five keys. A key sees only its own store, and the store's plan must be active.
All store API addresses · All APIs for developers
Frequently asked questions
Do I send the new quantity or the difference?
The new quantity in stock when your system is the source of truth for stock. The difference in delta when you record one movement such as a shipment arriving, because it does not wipe out a sale made in the store at the same moment.
Why was the request refused with variant_required?
Because the product has sizes and its stock is their sum. Send the size's id in variant_id; you find it in the products address.
Read next
Try the agent before you pay anything
The agent that will answer your customers is the one answering you now: ask it from the chat button here or on WhatsApp. Your account is free with no credit card, and the free trial on your own number or page is activated after you contact our team on customer-service WhatsApp.