Skip to main content

Create an Order

POST/api/v1/orders Open create order in the API Reference.

Create an Order to begin the standard Order workflow. The request requires a fromAddress, a toAddress, and exactly one entry in shipments — the Shipment carries the parcel Mailhub will rate and label. Create another Order for another box, or merge Orders into one Shipment later.

Use this operation when you want standard Order creation without rating during the create request. Use Create an Order with Rates when you want one Order created and its Shipment rated in the same request.

curl -s -X POST "${MAILHUB_API_BASE_URL}/api/v1/orders" \
-H "Authorization: Bearer ${MAILHUB_ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"fromAddress": {
"name": "Jane Sender",
"street1": "405 Fremont St",
"city": "Lander",
"state": "WY",
"zip": "82520",
"country": "US",
"phone": "5125550100"
},
"toAddress": {
"name": "John Recipient",
"street1": "405 Fremont St",
"city": "Lander",
"state": "WY",
"zip": "82520",
"country": "US",
"phone": "3035550100"
},
"shipments": [
{ "parcel": { "weight": 16, "length": 10, "width": 8, "height": 4 } }
]
}'

The public request schema requires fromAddress, toAddress, and the Shipment's parcel.weight. The current domestic validation also requires a name or company, street, city, state, postal code, country, and phone value; street2, email, and the remaining optional fields can be omitted. For a custom parcel, the current domestic validation expects positive length, width, and height; a recognized predefined package can supply dimensions.

Response​

A successful call returns 201 with the created Order, including a server-assigned id for the Order and for its Shipment:

{
"success": true,
"data": {
"id": "5f2c1a10-2b3d-4e5f-8a9b-0c1d2e3f4a5b",
"status": 0,
"isReturn": false,
"fromAddress": { "id": "...", "street1": "405 Fremont St", "city": "Lander", "state": "WY", "zip": "82520", "country": "US", "createdAt": "...", "updatedAt": "..." },
"toAddress": { "id": "...", "street1": "405 Fremont St", "city": "Lander", "state": "WY", "zip": "82520", "country": "US", "createdAt": "...", "updatedAt": "..." },
"shipments": [
{
"id": "b91a2c3d-4e5f-6a7b-8c9d-0e1f2a3b4c5d",
"status": "Unknown",
"isReturn": false,
"parcel": { "id": "...", "weight": 16, "length": 10, "width": 8, "height": 4 },
"createdAt": "...",
"updatedAt": "..."
}
],
"createdAt": "...",
"updatedAt": "..."
},
"errors": null
}

Continue the workflow​

Keep both identifiers: data.id (the Order) and data.shipments[0].id (the Shipment). The Shipment identifier is what Get Shipping Rates and Buy a Label require — rates and label purchase are not gated by the Order's status, so you can request rates immediately.

Validation failures​

400 means a required object is missing: fromAddress, toAddress, shipments (or an empty shipments array), or a Shipment's parcel. 422 means the request was readable but a value was rejected — a missing or invalid address field, a parcel outside the limits, or, with Validation.OneShipmentPerOrder, more than one entry in shipments. 401 indicates the bearer token is missing or no longer usable — see Authentication.

Optional: scope to a sub-account​

If your account uses sub-accounts, add X-SubAccount-Id: <sub-account-id> to tag the new Order (and its Shipment) with that sub-account. See Sub-account scoping.

Optional: make a retry safe​

Add an Idempotency-Key header to make an ambiguous create safe to repeat. Repeating the request with the same value returns the Order the first attempt created instead of creating a second one. Send it on the first attempt, choose a new value for each genuinely new Order, and keep it to 200 characters or fewer; values beginning with ingestion: are reserved and rejected with 422.

The request body is not compared, and the key is scoped to your account, not the sub-account: reusing it under a different X-SubAccount-Id still returns the first Order. See Order creation for the full retry rules. Without the header, a duplicate Order cannot be ruled out after an ambiguous outcome — do not blindly repeat the request.

This is not the merge-action key: merge actions compare the request, the action and the X-SubAccount-Id, and refuse a mismatch — see Repeat a merge action safely.