Sync products and stock from an ERP
The SKU is the link. Load once, upsert every item, copy pictures in the background, and move stock by delta.
The SKU is the link. Give every variant in the store the SKU your system uses. The design view, with a sequence diagram: Product and stock sync.
Scopes for this sync
Products and inventory: read and write. Add webhooks read and write to hear about the merchant's own changes.
First load
Read
GET /products?per_page=100page by page, passingmeta.next_cursorascursoruntil it isnull, and keep each product and variant id against its SKU.Upsert each item
GET /products/sku/{sku}. A 404 means a new item:POST /productswith the name and the variants (each withskuandpricein halalas),weight_gramswhen it ships, andstatus: activeto show it.- When found:
PATCH /products/sku/{sku}with only the fields that changed (keys you do not send stay). - URL-encode the SKU in the path. A SKU with a
/cannot be addressed there, because the path takes the SKU as one segment: find the product withGET /products?filter[sku]=and the encoded SKU, then use its id withPATCH /products/{id}. - Never send a quantity on a product: any
quantitykey is answered 422. Stock has its own path. - A product with sizes or colours:
optionswith their values, and each variant'svaluesholds one value key of every option.
A variant you send replaces the saved one: send its
sku,barcodeandsale_priceagain, or they are cleared (hiddenkeeps its value when left out).options,variantsandimageseach replace the whole set when sent.The fields of a product: Create product and Update product by SKU.
Pictures
Send public links in
images(orPOST /products/{id}/imageswith{url}). They are copied in the background: the answer lists the link inimages_pendingwith statuspending(and 202 for one picture), then it joinsimagesandproduct.updatedis sent. When the copy fails it turnsfailedwithimage_unreachable,too_many_imagesorcopy_failed. A product has 10 pictures, and a store has at most 50 links waiting at once (beyond that, 429images_queue_fullwithRetry-After). A copy job downloads for 60 seconds at most, so with many slow links some may endcopy_failed: send them again in a new write.Stock by delta
- Read the level:
GET /inventory?sku={sku}(orvariant_id), per branch. Branch ids come fromGET /branches. - Each movement in your system:
POST /inventory/adjustmentswith{"items":[{"sku":"…","mode":"increment","quantity":5}]}ordecrement, up to 100 lines a call, applied all or nothing, with anIdempotency-Keyfrom the movement number. Withoutbranch_idit goes to the default branch. mode: setmakes the level an exact number: for a stock count only, because it erases what the store sold between your read and your write.- A decrement below zero: 409
insufficient_stockwithavailable, and nothing is applied.
POST /inventory/adjustments Idempotency-Key: odoo-move-48213 {"items":[{"sku":"…","mode":"increment","quantity":5}]}The answer gives
quantity_afterper item. See Adjust stock.- Read the level:
The merchant's own changes
Subscribe to
product.updated,product.createdandproduct.deletedto mirror them in your system. See Webhooks.
Before you run it on the real store
- Every variant's SKU in the store is the one in your system.
- Prices are in halalas: 50 SAR is
5000. - Every stock movement sends an
Idempotency-Keyderived from the movement number. setonly for stock counts.