Idempotency and paging
Retry creates safely with Idempotency-Key, and sync lists with cursors and updated_since.
Idempotency
Networks fail. A create request can reach us, succeed, and then lose its response on the way back.
To retry such a request without creating the same thing twice, creates take an Idempotency-Key
header.
It is required on:
POST /productsPOST /products/{productId}/variants
curl -X POST https://api.bhaktibaazar.com/seller-api/v1/products \
-H "Authorization: Bearer $BHAKTI_BAAZAR_API_KEY" \
-H "Idempotency-Key: 9b2f6a3e-1c4d-4f7a-9e2b-5d8c0a1b2c3d" \
-H "Content-Type: application/json" \
-d @product.jsonHow it works:
- Use a new unique value for each create. A UUID is ideal. It must be 1 to 255 visible ASCII characters, without spaces.
- Keys are kept for 24 hours and belong to your seller account, whichever of your API keys sends them.
- Same key, same body: you get the first response again, with the header
Idempotent-Replayed: true. Nothing is created twice. - Same key, different body:
422 IDEMPOTENCY_KEY_REUSED. - A failed request is not kept. If the create fails (for example
400 VALIDATION_FAILED), fix the body and retry with the same key. - Still running:
409 IDEMPOTENCY_IN_PROGRESSmeans a request with this key is still running, or stopped before it finished. Check whether the product exists (for example withGET /products/by-code/{sellerProductCode}) before you retry.
Other writes are safe to repeat without a key:
PUT /inventoryandPUT /pricesset absolute values, so sending the same lines again changes nothing more. A repeated stock line that carriesexpectedStockfails withSTALE_STOCK, because the stock no longer matches it; itscurrentStockshows the value you set.- Accepting an order that is already accepted returns it unchanged.
- Preparing a cash-on-delivery invoice again returns the same invoice.
- Cancelling lines that are already cancelled skips them, so a repeated cancel returns the order.
- Adding the same self-ship tracking again returns the order with
200.
Paging
GET /products, GET /orders, GET /returns and GET /events return pages:
{
"data": [],
"nextCursor": "…",
"hasMore": true
}limitsets the page size: 1 to 100, default 50.- Pass
nextCursorback, unchanged, ascursorto get the next page.nextCursorisnullon the last page. A changed or made-up cursor gets400 INVALID_CURSOR. - Lists are in order of change, oldest first, so you can page to the end and stop.
Syncing with updated_since
GET /products, GET /orders and GET /returns take updated_since, so a sync only reads what
changed:
- Page through everything once, and store the newest
updatedAtyou saw. - Next time, pass it as
updated_sinceand page through again. - Repeat, storing the newest
updatedAteach time.
updated_since means "changed at or after", so the record with exactly that time comes back again.
Match records by id, and treat a record you already have as an update.
What counts as a change:
- Products: the product itself, any of its variants (stock included, so every order that reduces
stock moves the product) or its deletion. Pass
include_deleted=trueto also get deleted products, withstatus: "deleted", so your sync can remove them. A deleted variant drops out of its product'svariants. - Orders: the order, any of its lines, its shipment (courier scans included) or one of its returns. Busy orders come back often while they are in transit.
An edit that changes only a product's attributes, made in the seller portal, does not yet count as a change. Your sync sees it the next time something else on that product changes. Attribute edits made through the API do count.
The event list
GET /events pages the same way, but filters with since instead of updated_since, and can filter
by type. It needs the webhooks:manage scope. See Webhooks.