Place an Order
This guide walks through creating an order programmatically.
Prerequisites
- An API key with scopes
catalog:readandorders:write - A
cart_idfrom the commerce cart flow (created via the storefront or/commerce-api/v1/cart)
Flow
- Look up the product (optional — to display to your user)
- Add items to a cart (via the commerce-api cart endpoints)
- POST to
/orderswith billing, shipping, and payment info - Store the returned order number for the customer
Example (Node.js)
const API = 'https://api.spectradiag.com/api/v1';
const headers = {
'Authorization': 'Bearer spk_live_xxx',
'Content-Type': 'application/json',
};
// Assume you already have a cart_id with items in it.
const response = await fetch(`${API}/orders`, {
method: 'POST',
headers,
body: JSON.stringify({
cart_id: 'abc-123-xyz',
billing: {
name: 'Alice Buyer',
email: 'alice@example.com',
phone: '555-1234',
address1: '123 Main St',
city: 'Brooklyn',
state: 'NY',
zip: '11201',
country: 'US',
},
shipping: {
name: 'Alice Buyer',
address1: '123 Main St',
city: 'Brooklyn',
state: 'NY',
zip: '11201',
country: 'US',
},
shipping_method: {
method: 'ground',
carrier: 'UPS',
service: 'UPS Ground',
cost: 8.99,
},
payment: {
method: 'stripe',
gateway_id: 'pi_xxx', // Stripe payment intent ID
},
}),
});
const { data: order } = await response.json();
console.log('Order created:', order.order_number);Important notes
- Tax is calculated server-side — ignore any
tax_amountyou send; the API recomputes it from the shipping state and tenant tax config. - Promo codes — include
payment.promo_codeto apply a promotion. Validation happens server-side. - Gift cards — include
payment.gift_card_codeto redeem a gift card balance. - Test orders — if you use an
spk_test_key, the order is flaggedis_test = trueand doesn't trigger customer emails.
Response
{
"success": true,
"data": {
"id": 1234,
"order_number": "ORD-20260515-0042",
"status": "pending",
"payment_status": "captured",
"grand_total": 1234.56,
"is_test": false,
"items": [...]
}
}Next steps
- Listen for
order.createdwebhooks to sync the order into your system - Listen for
order.shippedandorder.deliveredto update your UI - Use
PATCH /orders/{id}/statusto change status later