Skip to main content

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.

FieldTypeRequiredDescription
customerStringYesID of the customer placing the order.
orderStatusStringYespending, processing, partially fulfilled, fulfilled, restocked or cancelled.
paymentStatusStringYesunpaid, authorized, declined, partially paid, paid, partially refunded or refunded.
lineItemsArrayYesItems in the order. See Line Item Object.
billingAddressStringNoID of one of the customer's saved billing addresses (the company's, for B2B customers).
newBillingAddressObjectNoA new billing address to save and use. See New Billing Address Object.
shippingAddressIdStringNoID of one of the customer's saved shipping addresses.
newShippingAddressObjectNoA new shipping address to save and use. See New Shipping Address Object.
taxAmountNumberNoTax amount. Default is 0.
shippingCostNumberNoShipping cost, zero or more. Default is 0.
currencyObjectNoCurrency of the amounts, with currency (code) and symbol. Both are required when sent.
paymentTermStringNoID of a payment term assigned to the customer's company.
orderedAtStringNoDate and time the order was placed. Default is now.
refundedAmountNumberNoAmount already refunded. Default is 0.
fulfilledItemsArrayNoShipments already made. See Fulfilled Item Object.
metaFieldsArrayNoCustom field values, each with code and value. See Metafields.

Line Item Object​

FieldTypeRequiredDescription
productIdStringYesID of the product.
variantIdStringNoID of the variant, for products with variants.
quantityNumberYesQuantity ordered, zero or more.
priceNumberYesUnit price.
discountAmountNumberNoDiscount taken off this line's total.
fulfilledQuantityNumberNoQuantity already shipped. Default is 0.
returnedBooleanNoWhether the line has been returned. Default is false.

New Billing Address Object​

FieldTypeRequiredDescription
firstNameStringYesFirst name, 3 to 20 characters.
lastNameStringYesLast name, 3 to 20 characters. Can be an empty string.
address1StringYesStreet address, up to 100 characters.
address2StringNoAdditional address line, up to 100 characters.
cityStringYesCity.
stateStringYesState code, for example TX.
countryStringYesCountry code, for example US.
zipcodeStringYesPostal code.
phoneNumberStringNoPhone number.
companyNameStringNoCompany name.
companyEmailStringNoCompany 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​

FieldTypeRequiredDescription
itemsArrayNoShipped lines, each with lineItemId and quantity (required).
carrierStringNoCarrier name.
trackingNumberStringNoTracking number.
trackingUrlStringNoTracking page URL.
fulfilledAtStringNoShipment 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": false and 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​

FieldTypeDescription
successBooleanWhether the order was created.
messageStringResult message.
dataObjectThe 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. subTotal is the sum of the line totals, and total is subTotal + taxAmount + shippingCost.
  • If currency is 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 newBillingAddress or newShippingAddress is also saved to the customer's address book.
  • Creating an order sends the order confirmation email to the customer and the store.