Create a purchase order
Creates a draft purchase order for one vendor from customer order lines or for stock, using Shopify products by SKU, template configurations or new products, which are created in Shopify when the purchase order is created (lines[].kind). Stock orders require store_location_id. API keys cannot enter costs: order lines use their recorded costs and other lines use 0. Send the purchase order with POST /purchase-orders/{id}/send.
Required access
- API key
- Manage purchase orderspermission
- Request limit
- Counts as 5 requests. Each key has a capacity of 15, restored at 0.6 a second.
Idempotent-Replayed: true. Responses are saved for 24 hours.Headers
Bearer and your key, opk_….
Up to 100 characters (letters, digits, - _ : .). Kept for 24 hours.
application/json. A body is at most 256 KB.
Body
JSONWhere it is delivered, as printed on the purchase order: to a location, its address from GET /locations; to a warehouse, its address from GET /warehouses; to the customer, their address. Left out on a store delivery: the warehouse’s address (warehouse_id), else the location’s (store_location_id). Required for a customer or dropship delivery.
Left out: store.
One of store, customer, dropship.
Leave prices off the copy the vendor gets.
At most 300 lines, each a thing to buy (kind) and a quantity; an order line no more than it still needs.
new_product: the category’s id, from GET /categories or POST /categories; its name becomes the Shopify product’s type. Send this or category_slug, not both. Left out, the product has no type, and the line can’t be given one later.
new_product: the category’s slug, from GET /categories.
order_line: an option’s key from the line’s PO components; left out for the product itself.
The line’s Item notes, as the workbench and the edit page take them, shown with the line on the purchase order’s page. Up to 500 characters.
Any casing. Default order_line.
One of order_line, stock, new_product, template.
Unit cost, at most 2 decimals. Needs “Enter costs and charges”; otherwise an order line takes its own cost and any other line 0.
Units to buy, a whole number above 0.
new_product: its selling price. Needs Edit catalog prices. Left out, the product is made at 0 and the line can’t change it later: set it in Shopify, or send a products import draft (POST /imports) for the merchant to sign off.
new_product: also make a product template of it, to quote it again.
template: the options chosen, each by its field_id from the template’s options in GET /product-templates/{id}.
The same id as field_id, by its first name. Send one of them.
The option: its field_id from GET /product-templates/{id}. Send this or definition_id.
A dropdown’s value: its option_id from the option’s values.
A number or text option’s value.
stock: the SKU of the Shopify variant (exact, any case); send this, variant_id, or both. new_product, template: the new item’s SKU. A new_product SKU that a Shopify product has already is 409 SKU_EXISTS: send a stock line with it.
order_line: the order line’s id.
template: an active product template.
new_product: the product’s name in Shopify.
stock: the Shopify variant (an id or gid, from GET /products/{id}): alone for a product with no SKU, or with sku to pick one when several have it.
Needs “Enter costs and charges”; otherwise 0.
The Shopify location that receives the stock: an id from GET /locations (one of the caller’s). Required for a stock purchase order (and to take a store delivery’s address from it), unless the caller can use only one location: then that one.
Needs “Enter costs and charges”; otherwise 0.
The vendor by its name (its display_name in GET /vendors; case and spacing don’t matter), instead of vendor_id. A name two vendors answer to is refused, naming both (error.matches); none is 404.
Every line’s vendor must be this one: an id from GET /vendors. Send this or vendor.
A store delivery to a warehouse: an id from GET /warehouses. Left out: delivered to the location itself.
Returns
Created: content_version, costs_hidden, delivery_address, delivery_type, id, lines, number, shipping, status, store_location_id and more
Accepted: the write is done, but its record couldn’t be read back. Don’t send it again: read it with `read`.: charge_id, content_version, done, id, message, number, payment_id, read, refund, reopened and more
Errors
Errors use { "error": { "code", "message" } }. Use code to handle the error. View all error codes.
The request isn’t valid (see error.code), or the API version isn’t supported.
No valid access token or API key.
The store’s subscription isn’t active.
Not allowed: the API is off for this store, or the caller lacks the scope or permission.
Not found, or not visible to this caller.
Wrong method for this path; Allow lists every method the path takes.
The request body didn’t arrive in time.
The same Idempotency-Key is still being processed (REQUEST_IN_PROGRESS), its outcome is unknown (OUTCOME_UNKNOWN: check the record), or the record changed since it was read.
The request body is too large.
The request is valid JSON but can’t be done (a rule of the store refuses it), or the Idempotency-Key was used with a different body.
The app is older than the oldest version still served (error.code CLIENT_TOO_OLD); see error.min_version and error.upgrade_url.
Over a rate limit; wait Retry-After seconds.
Something went wrong on our side. A write may have partly happened: check the record before retrying it.
Busy, switched off, or billing couldn’t be checked; wait Retry-After seconds.