Create Order
Creates a new order for an existing customer using the prices you provide. Use it to import orders placed outside the storefront, for example from an ERP.
HTTP Request
- URL:
/orders - Method:
POST - Headers:
accessToken: Required. Your API access token.Content-Type:application/json
- Required scope:
READ_WRITE_ORDER
Request Body
The request body is a JSON object with the order details. Send either billingAddress or newBillingAddress, and either shippingAddressId or newShippingAddress.
| Field | Type | Required | Description |
|---|---|---|---|
customer | String | Yes | ID of the customer placing the order. |
orderStatus | String | Yes | pending, processing, partially fulfilled, fulfilled, restocked or cancelled. |
paymentStatus | String | Yes | unpaid, authorized, declined, partially paid, paid, partially refunded or refunded. |
lineItems | Array | Yes | Items in the order. See Line Item Object. |
billingAddress | String | No | ID of one of the customer's saved billing addresses (the company's, for B2B customers). |
newBillingAddress | Object | No | A new billing address to save and use. See New Billing Address Object. |
shippingAddressId | String | No | ID of one of the customer's saved shipping addresses. |
newShippingAddress | Object | No | A new shipping address to save and use. See New Shipping Address Object. |
taxAmount | Number | No | Tax amount. Default is 0. |
shippingCost | Number | No | Shipping cost, zero or more. Default is 0. |
currency | Object | No | Currency of the amounts, with currency (code) and symbol. Both are required when sent. |
paymentTerm | String | No | ID of a payment term assigned to the customer's company. |
orderedAt | String | No | Date and time the order was placed. Default is now. |
refundedAmount | Number | No | Amount already refunded. Default is 0. |
fulfilledItems | Array | No | Shipments already made. See Fulfilled Item Object. |
metaFields | Array | No | Custom field values, each with code and value. See Metafields. |
Line Item Object
| Field | Type | Required | Description |
|---|---|---|---|
productId | String | Yes | ID of the product. |
variantId | String | No | ID of the variant, for products with variants. |
quantity | Number | Yes | Quantity ordered, zero or more. |
price | Number | Yes | Unit price. |
discountAmount | Number | No | Discount taken off this line's total. |
fulfilledQuantity | Number | No | Quantity already shipped. Default is 0. |
returned | Boolean | No | Whether the line has been returned. Default is false. |
New Billing Address Object
| Field | Type | Required | Description |
|---|---|---|---|
firstName | String | Yes | First name, 3 to 20 characters. |
lastName | String | Yes | Last name, 3 to 20 characters. Can be an empty string. |
address1 | String | Yes | Street address, up to 100 characters. |
address2 | String | No | Additional address line, up to 100 characters. |
city | String | Yes | City. |
state | String | Yes | State code, for example TX. |
country | String | Yes | Country code, for example US. |
zipcode | String | Yes | Postal code. |
phoneNumber | String | No | Phone number. |
companyName | String | No | Company name. |
companyEmail | String | No | Company email address. |
New Shipping Address Object
Same fields as the New Billing Address Object. firstName needs at least 1 character and lastName can be any length.
Fulfilled Item Object
| Field | Type | Required | Description |
|---|---|---|---|
items | Array | No | Shipped lines, each with lineItemId and quantity (required). |
carrier | String | No | Carrier name. |
trackingNumber | String | No | Tracking number. |
trackingUrl | String | No | Tracking page URL. |
fulfilledAt | String | No | Shipment date. |
cURL Example
curl --location '<BASE_URL>/orders' \
--header 'accessToken: <ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
"customer": "664dec6cd5775459152d4926",
"orderStatus": "pending",
"paymentStatus": "unpaid",
"billingAddress": "664dec6cd5775459152d4923",
"shippingAddressId": "664dec6cd5775459152d4924",
"taxAmount": 43.2,
"shippingCost": 12,
"lineItems": [
{ "productId": "663a0cbe516313e5bc94ab30", "quantity": 12, "price": 45 }
],
"metaFields": [
{ "code": "erpOrderId", "value": "SO-88213" }
]
}'
Response
- 200 OK: The order was created. If the customer, address or payment term cannot be found, the response has
"success": falseand a message explaining why. - 400 Bad Request: The access token is missing or invalid, a required field is missing or invalid, or a product does not exist.
Sample JSON Response
{
"success": true,
"message": "Order created Successfully",
"data": {
"id": "664f2310d5775459152d6dd8",
"entityId": "ORD-1043",
"company": "664dec6cd5775459152d4922",
"customer": "664dec6cd5775459152d4926",
"customerDetails": {
"firstName": "Maria",
"lastName": "Lopez",
"email": "maria.lopez@northwindsupply.com",
"phoneNumber": "512-555-0142"
},
"lineItems": [
{
"id": "664f2310d5775459152d6ddb",
"productId": "663a0cbe516313e5bc94ab30",
"name": "Safety Glasses",
"sku": "SFTY-4006",
"productSku": "SFTY-4006",
"quantity": 12,
"price": 45,
"extendedTotalPrice": 540,
"fulfilledQuantity": 0,
"returned": false
}
],
"currency": { "currency": "USD", "symbol": "$" },
"payments": [],
"paymentStatus": "unpaid",
"orderStatus": "pending",
"taxAmount": 43.2,
"shippingCost": 12,
"subTotal": 540,
"total": 595.2,
"approved": true,
"createdBy": { "name": "ERP Connector api", "type": "api" },
"metaFields": [
{ "id": "664f2310d5775459152d6de2", "code": "erpOrderId", "label": "ERP Order ID", "value": "SO-88213" }
],
"createdAt": "2024-05-23T11:05:52.550Z",
"updatedAt": "2024-05-23T11:05:52.550Z"
}
}
Response Details
Order Data
| Field | Type | Description |
|---|---|---|
success | Boolean | Whether the order was created. |
message | String | Result message. |
data | Object | The new order. See Get Order for all fields. |
Notes
- Product name, SKU, image and options are copied from the product.
- Each line total is
price × quantity − discountAmount.subTotalis the sum of the line totals, andtotalissubTotal + taxAmount + shippingCost. - If
currencyis different from the store currency and an exchange rate is set up for it, the amounts you send are treated as amounts in that currency and converted to the store currency. - A new address sent in
newBillingAddressornewShippingAddressis also saved to the customer's address book. - Creating an order sends the order confirmation email to the customer and the store.