Create a Purchase Order
This guide walks through the full lifecycle of a purchase order (PO) over
the GoodDay API: creating it with line items, updating its status to
open, and verifying it with a fetch.
All requests assume you have a bearer token with scopes
read:purchase_orders and write:purchase_orders. If you need help
setting that up, start with the authentication guide.
Base URL for every request:
https://api.gooddayai.com/v1
All endpoints return JSON with a data envelope (single-object responses)
or a data + pagination envelope (list responses).
Step 1 — Create the PO
POST a new purchase order with its blocks and line items in one request.
The request below creates a PO for vendor companyId: 42, with one
fulfillment block targeting location 3 and two line items.
curl -X POST https://api.gooddayai.com/v1/purchase-orders \
-H "Authorization: Bearer gd_yourTokenValueHere" \
-H "Content-Type: application/json" \
-d '{
"companyId": 42,
"purchaseOrderNumber": "PO-2026-0001",
"purchaseOrderDate": "2026-04-21T00:00:00.000Z",
"currencyId": 1,
"internalNotes": "Q2 restock for West Coast warehouse",
"blocks": [
{
"shipToLocationId": 3,
"expectedFulfillmentDate": "2026-05-15T00:00:00.000Z",
"lineItems": [
{ "itemId": 1001, "unitsOrdered": 200, "vendorPrice": 12.50 },
{ "itemId": 1002, "unitsOrdered": 150, "vendorPrice": 8.75 }
]
}
]
}'
Response (trimmed; the auto-seeded empty default block is omitted here for brevity — see the "Heads up" note below):
{
"data": {
"id": 789,
"purchaseOrderNumber": "PO-2026-0001",
"status": "draft",
"company": { "id": 42, "name": "Acme Supplies" },
"purchaseOrderBlocks": [
{
"id": 901,
"shipToLocation": { "id": 3, "name": "West Coast DC" },
"lineItems": [
{ "id": 5001, "itemId": 1001, "unitsOrdered": 200, "vendorPrice": 12.5 },
{ "id": 5002, "itemId": 1002, "unitsOrdered": 150, "vendorPrice": 8.75 }
]
}
]
}
}
Note the PO comes back with status: "draft". You can only mutate a PO's
line items or blocks while it is in the open state, so move it to
open as the next step before editing.
Heads up on purchaseOrderBlocks: every newly created PO includes an
auto-seeded empty default block in addition to the blocks you supplied,
so a request with one block returns two blocks in the response. When you
add line items in a later step, make sure you target the id of the
block you created, not the empty one.
JavaScript
const response = await fetch('https://api.gooddayai.com/v1/purchase-orders', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.GOODDAY_API_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
companyId: 42,
purchaseOrderNumber: 'PO-2026-0001',
purchaseOrderDate: new Date('2026-04-21').toISOString(),
currencyId: 1,
blocks: [
{
shipToLocationId: 3,
expectedFulfillmentDate: new Date('2026-05-15').toISOString(),
lineItems: [
{ itemId: 1001, unitsOrdered: 200, vendorPrice: 12.5 },
{ itemId: 1002, unitsOrdered: 150, vendorPrice: 8.75 },
],
},
],
}),
});
const { data: purchaseOrder } = await response.json();
console.log('Created PO', purchaseOrder.id, 'status=', purchaseOrder.status);
Python
import os
import requests
resp = requests.post(
"https://api.gooddayai.com/v1/purchase-orders",
headers={
"Authorization": f"Bearer {os.environ['GOODDAY_API_TOKEN']}",
"Content-Type": "application/json",
},
json={
"companyId": 42,
"purchaseOrderNumber": "PO-2026-0001",
"purchaseOrderDate": "2026-04-21T00:00:00.000Z",
"currencyId": 1,
"blocks": [
{
"shipToLocationId": 3,
"expectedFulfillmentDate": "2026-05-15T00:00:00.000Z",
"lineItems": [
{"itemId": 1001, "unitsOrdered": 200, "vendorPrice": 12.50},
{"itemId": 1002, "unitsOrdered": 150, "vendorPrice": 8.75},
],
}
],
},
timeout=30,
)
resp.raise_for_status()
po = resp.json()["data"]
print(f"Created PO {po['id']} status={po['status']}")
Step 2 — Move the PO to open
Use PATCH /:id/status to advance the PO through its lifecycle. Valid
status transitions are:
draft -> open -> closed
draft -> cancelled
open -> cancelled
closed and cancelled are terminal — there is no transition out of
either state. If you need further changes after closing or cancelling a
PO, create a new one.
curl -X PATCH https://api.gooddayai.com/v1/purchase-orders/789/status \
-H "Authorization: Bearer gd_yourTokenValueHere" \
-H "Content-Type: application/json" \
-d '{"status": "open"}'
Response:
{
"data": {
"id": 789,
"status": "open",
"statusChangedAt": "2026-04-21T16:14:00.000Z"
}
}
Step 3 — Verify the PO
Fetch the PO by ID to confirm its state and read back the persisted line items, blocks, and computed totals.
curl https://api.gooddayai.com/v1/purchase-orders/789 \
-H "Authorization: Bearer gd_yourTokenValueHere"
{
"data": {
"id": 789,
"status": "open",
"subTotalPrice": 3812.5,
"totalPrice": 3812.5,
"purchaseOrderBlocks": [
{
"id": 901,
"lineItems": [
{ "id": 5001, "unitsOrdered": 200, "vendorPrice": 12.5 },
{ "id": 5002, "unitsOrdered": 150, "vendorPrice": 8.75 }
]
}
]
}
}
Editing a PO after creation
While the PO is in the open state you can:
PATCH /purchase-orders/:idUpdate header fields (notes, dates, payment terms, custom fields).POST /purchase-orders/:id/blocksAdd another fulfillment block (different ship-to location or date).POST /purchase-orders/:id/line-itemsAdd line items to an existing block.PATCH /purchase-orders/:id/line-items/:lineItemIdUpdate a line item'sunitsOrderedorvendorPrice.DELETE /purchase-orders/:id/line-items/:lineItemIdRemove a line item.
Once the PO transitions to closed or cancelled, these mutations
return a 409 Conflict. Those transitions are terminal — create a new
PO if you need further changes.
Common errors
| Status | Meaning |
|---|---|
| 400 | Malformed request (bad JSON, invalid status transition) |
| 401 | Bad or missing bearer token |
| 403 | Token lacks the required scope (e.g. read:purchase_orders or write:purchase_orders) |
| 404 | PO, block, or line item does not exist for this merchant |
| 409 | PO is not open — cannot modify blocks or line items |
| 422 | Required field missing or DTO validation failed (e.g. negative unitsOrdered) |
Next steps
- List and filter sales orders
- Explore receipts and shipments in the full API reference:
POST /purchase-orders/:id/shipments,POST /purchase-orders/:id/line-items/:lineItemId/receipts.