Sales-order intake API
- Available on
- Trial
- Pro
- Enterprise
- Who can do this
- Create or revoke the API key a system sends orders withRoles: Administrator
Permission: organization:write
- Create or revoke the API key a system sends orders withRoles: Administrator
A webshop, an EDI bridge or another source system sends werkplan a sales order with one request, and werkplan adds it as a draft sales order. Someone in your company then checks it and confirms it on the Sales orders screen; nothing is planned or made until then.
Before you start
Section titled “Before you start”Make an API key for the system on the API keys screen, one key for each system that sends orders. The key is shown once, when you make it: copy it into the sending system then. A key sends sales orders in and does nothing else.
Send an order
Section titled “Send an order”POST https://console.werkplan.app/api/v1/intake/sales-ordersX-API-Key: wk_live_…Content-Type: application/jsonhttps://console.werkplan.appis the address you sign in to werkplan at.X-API-Keycarries the key. The request carries no other sign-in.- Send the order as JSON, with a
Content-Lengthheader, not in chunks. A request is at most 1 MiB. - Call it from your server, not from a web page in a browser: a browser’s page can’t send the key’s header to werkplan.
A short order, as werkplan’s own tests send it:
{ "externalReference": "WEB-100", "customer": { "customerNumber": "CUST-1", "name": "Web Buyer" }, "lines": [ { "sku": "WID-4b1f0e2a", "quantity": 2, "unitPrice": 9.99 } ]}An order with a shipping address and the customer’s own reference:
{ "externalReference": "WEB-1", "customer": { "customerNumber": "CUST-1", "name": "Web Buyer", "email": "buyer@example.com" }, "shippingAddress": "12 High Street", "customerReference": "THEIR-PO-1", "lines": [ { "sku": "WID-4b1f0e2a", "quantity": 4, "unitPrice": 12.50 } ]}The order’s fields
Section titled “The order’s fields”| Field | Required | What it holds |
|---|---|---|
externalReference |
Required | Your system’s own id for the order, at most 100 characters. Sent again with the same key, it returns the order it made, rather than a second one. |
customer |
Required | Who orders: the fields below. |
customer.customerNumber |
Required | The customer’s number in werkplan, at most 50 characters. |
customer.name |
When the number is unknown | The name werkplan adds the customer with, at most 255 characters. Ignored for a customer werkplan knows. |
customer.email |
Optional | The email address werkplan adds the customer with, at most 255 characters. |
requestedDeliveryDate |
Optional | The day the customer wants the order, YYYY-MM-DD, for the order and each of its lines. |
shippingAddress |
Optional | Where to deliver this order, at most 500 characters. It stays the order’s address when the order is confirmed. |
customerReference |
Optional | The customer’s own number for the order, such as their purchase order, at most 100 characters. |
notes |
Optional | Notes, at most 2,000 characters. |
lines |
Required | From 1 to 500 lines, each with the fields below. |
lines[].sku |
Required | The SKU of the item ordered, at most 50 characters, matched exactly. |
lines[].quantity |
Required | How many, more than zero. |
lines[].unitPrice |
Optional | The price of one unit, zero or more. |
lines[].discountPercent |
Optional | A discount from 0 to 100 percent. |
lines[].taxRatePercent |
Optional | The tax rate from 0 to 100 percent. |
The answer
Section titled “The answer”201 Created when werkplan adds the order, and 200 OK when this key sent the same externalReference before. The body names the sales order either way:
{ "salesOrderId": "0193a8c4-5f0e-7c4a-9b1d-2e6f8a0c3d51", "orderNumber": "SO-0000042", "externalReference": "WEB-100", "alreadyExisted": false}alreadyExisted is true on a 200, which returns the order the first request made. werkplan doesn’t compare the second request with the first: to change an order it has, change it on the Sales orders screen. Retry a request whose answer you didn’t get with the same externalReference, and the customer gets one order.
What werkplan does with an order
Section titled “What werkplan does with an order”- It adds a draft sales order, with your organisation’s next order number and today as its order date.
- It finds the customer by
customerNumber. A number werkplan doesn’t know adds a customer withnameandemail; a known customer keeps the name and email werkplan has. - It finds each line’s item by its SKU: anything you make or buy. An item that isn’t active is refused.
- A line without a price takes the lowest price of the price lists the customer is on that apply that day, or else the item’s sales price, or stays without a price. A line without a discount takes none when a price list prices it, or else the customer’s discount. A line without a tax rate gets 0.
- It checks every line before it adds anything: a refused request adds no order and no customer.
Confirming the draft on the Sales orders screen decides what to make: it raises production orders for the manufactured items that the shelf and the supply on its way don’t cover.
Errors
Section titled “Errors”| Status | code |
When |
|---|---|---|
400 |
WP-1001 |
A field breaks a rule above, such as no lines or more than 500; the body isn’t JSON; no item has a line’s SKU; or the customer’s number is unknown and customer.name is missing. |
401 |
WP-4011 |
The X-API-Key header is missing, or its key is wrong or revoked. |
402 |
WP-4012 |
Your organisation’s trial or subscription has ended. |
403 |
WP-4002 |
Your organisation is disabled. |
411 |
WP-1005 |
The request is sent in chunks, with a Transfer-Encoding header, rather than with a Content-Length. |
413 |
WP-1004 |
The request is larger than 1 MiB. |
422 |
WP-5007 |
A line’s item isn’t active. |
429 |
WP-4029 |
The key sent more than 300 requests in a minute. Wait a minute and send it again. |
Every error body carries its code and a message that says what is wrong. An answer about the key, the organisation, the request’s size or the limit (401, 402, 403, 411, 413, 429) also carries a title. An answer about the order (400, 422) also carries path, timestamp and traceId, and a request that breaks a field’s rule lists each field with its message under details:
{ "code": "WP-1001", "message": "Validation failed", "details": { "lines": "At least one line is required" }}Limits
Section titled “Limits”- 300 requests a minute for each key, counted by the clock’s minute.
- 500 lines and 1 MiB for each order.
- One order for each
externalReferenceand key. Two keys sending the same reference each make an order of their own, and an order sent again with a key that replaced an old one is made again.
Still stuck? Write to support@example.com.