Browse all articles

Purchasing API

Last updated

With the Purchasing add-on on, ChannelDock’s REST API v2 has extra endpoints for purchasing. Use them to read the advice in another system, keep supplier products and planning settings in step with your ERP, upload supplier stock, or create and place purchase orders. The API uses the same rules and checks as the Purchasing screens.

Steps

  1. Create or open an API key. Go to Settings > API & webhooks, or click API keys and webhooks on Purchasing > Settings > Integrations. See ChannelDock REST API Documentation.
  2. Set the Purchasing scopes. In the key dialog, under Endpoint permissions, find Purchasing and tick the scopes the key needs:
Scope Allows
READ Every GET: advice, orders, supplier products, planning settings, forecasts, order moments
WRITE Create and change drafts, supplier products, supplier stock and planning settings
PLACE Place a purchase order, which creates the inbound delivery
  1. Call the endpoints. The base address is /portal/api/v2/seller/purchasing/. Authentication, rate limits and the answer format are the same as the rest of API v2.

Endpoints

Method Endpoint What it does
GET advice The latest advice per product. Filters supplier_id, product_id, advised_only=1.
GET purchase-orders Proposals, drafts, orders awaiting approval and placed orders. Filters status, supplier_id, updated_since.
GET purchase-orders/{id} One order with its lines.
POST purchase-orders Turn a proposal into a draft (proposal_id) or create a new draft (supplier_id and lines).
PUT purchase-orders/{id}/lines Set quantities from 0 to 1,000,000. Quantity 0 removes a line; for a product that is not on the order it is skipped.
DELETE purchase-orders/{id} Delete a draft.
POST purchase-orders/{id}/place Place the order. Optional number, center_id, expected_date.
GET, POST, PUT, DELETE supplier-products List, link, update and unlink supplier products. Unlinking keeps the link as never buy (kept_as: never_buy); linking the supplier again brings it back.
POST, GET supplier-stock Upload supplier stock, or see recent stock updates.
GET, PUT planning-settings Read or change the planning settings per product.
GET forecasts The forecast per day, week or month, up to 182 days.
GET order-moments The planned order moments per supplier.

A line is { "product_id": 12, "quantity": 5 }, or names the product with supplier_sku, sku or ean. Up to 2,000 lines per call. Lists take page (1 to 100,000) and page_size (1 to 250, default 50). A value outside those ranges, an unknown status or other filter value, or a date that is not a real date is refused with 400 and the name of the field.

Place orders safely

Placing needs an idempotency key. Send the header Idempotency-Key with 8 to 60 letters, digits, - or _ (or idempotency_key in the body). If your system retries with the same key and the same body, it gets the first answer back with "idempotent_replay": true, and no second delivery is created. The same key with another body is refused. Keys are kept 7 days. When two calls with the same key arrive at the same time, the second waits for the first and gets its answer. The key of a place belongs to that order: the same key on another order is refused. You can also send a key on POST purchase-orders.

Approval rules and budgets apply as on screen. When an order needs approval, the place call sends it for approval instead (status awaiting_approval), unless the user behind the key may approve it; a budget that blocks refuses the call.

Placed orders and the warehouse

Placed orders carry wms_export with the export status to your warehouse system: exported, failed, in_fc, waiting, own_warehouse, received or unknown. See Warehouse export status per purchase order.

Good to know

  • A key without a Purchasing row may read and write, but never place. Placing is a deliberate choice per key.
  • A sub-user’s own Purchasing rights (view, edit, place) apply on top of the key’s scopes.
  • Errors: 400 for bad input with the field name (also for a body that is not valid JSON), 403 when the add-on is off, in the read-only period, or a scope or right is missing, 404 for an id that does not exist or belongs to another account.
  • During the 90-day read-only period after the add-on is switched off, GET calls still work and every write answers 403.
  • Every change through the API is in the change history with the API as the source.
  • The inbound delivery of a placed purchase order cannot be deleted with API v2: DELETE on the delivery answers 409. Close or cancel it on the order’s inbound page in Purchasing.
  • The API card on Purchasing > Settings > Integrations shows the base address and, under Endpoints, all 17 endpoints.

Related articles


Was this helpful?

Related articles