import { createAdminClient } from '@spree/admin-sdk'
const client = createAdminClient({
baseUrl: 'https://your-store.com',
secretKey: 'sk_xxx',
})
// One-shot order create: customer, items, addresses, market, channel,
// notes, metadata, and a coupon code in a single call. Everything
// except `email` is optional.
const order = await client.orders.create({
email: 'jane@example.com',
customer_id: 'cus_UkLWZg9DAJ', // Existing customer; omit for guest orders
use_customer_default_address: false, // true to copy the customer's saved addresses
currency: 'USD',
market_id: 'mkt_UkLWZg9DAJ',
channel_id: 'ch_UkLWZg9DAJ', // Optional — defaults to the store's primary channel
locale: 'en-US',
// Pin the order's preferred fulfillment location. Order Routing's
// built-in PreferredLocation rule ranks this location first when
// it stocks the cart's items; if it doesn't, routing falls back
// to the next rule (Minimize Splits → Default Location).
preferred_stock_location_id: 'sloc_UkLWZg9DAJ',
customer_note: 'Please leave at the front desk.',
// Rich text: send HTML. Reads return this as plain text, plus
// `internal_note_html` with the markup.
internal_note: '<p>VIP customer — handle with care.</p>',
metadata: {
external_reference: 'subscription_invoice_2026_04',
source: 'recurring-engine',
},
// Items: each variant_id + quantity. Optional metadata per line.
items: [
{ variant_id: 'variant_k5nR8xLq', quantity: 2 },
{ variant_id: 'variant_QXyZ12abCD', quantity: 1, metadata: { gift: true } },
],
// Provide addresses inline OR by ID (existing customer addresses).
shipping_address: {
first_name: 'Jane',
last_name: 'Doe',
address1: '350 Fifth Avenue',
address2: 'Floor 42',
city: 'New York',
postal_code: '10118',
country_code: 'US',
state_code: 'NY',
phone: '+1 212 555 1234',
company: 'Acme Inc.',
},
// shipping_address_id: 'addr_UkLWZg9DAJ', // alternative to inline
billing_address: {
first_name: 'Jane',
last_name: 'Doe',
address1: '350 Fifth Avenue',
city: 'New York',
postal_code: '10118',
country_code: 'US',
state_code: 'NY',
phone: '+1 212 555 1234',
},
// billing_address_id: 'addr_UkLWZg9DAJ',
// Optional. Invalid codes are non-fatal — the order is created either way.
coupon_code: 'WELCOME10',
})spree api post /orders -d '{"email":"jane@example.com","customer_id":"cus_UkLWZg9DAJ","use_customer_default_address":false,"currency":"USD","market_id":"mkt_UkLWZg9DAJ","channel_id":"ch_UkLWZg9DAJ","locale":"en-US","preferred_stock_location_id":"sloc_UkLWZg9DAJ","customer_note":"Please leave at the front desk.","internal_note":"<p>VIP customer — handle with care.</p>","metadata":{"external_reference":"subscription_invoice_2026_04","source":"recurring-engine"},"items":[{"variant_id":"variant_k5nR8xLq","quantity":2},{"variant_id":"variant_QXyZ12abCD","quantity":1,"metadata":{"gift":true}}],"shipping_address":{"first_name":"Jane","last_name":"Doe","address1":"350 Fifth Avenue","address2":"Floor 42","city":"New York","postal_code":"10118","country_code":"US","state_code":"NY","phone":"+1 212 555 1234","company":"Acme Inc."},"billing_address":{"first_name":"Jane","last_name":"Doe","address1":"350 Fifth Avenue","city":"New York","postal_code":"10118","country_code":"US","state_code":"NY","phone":"+1 212 555 1234"},"coupon_code":"WELCOME10"}'{
"id": "or_gbHJdmfrXB",
"market_id": "mkt_UkLWZg9DAJ",
"withdrawal_period_ends_at": null,
"within_withdrawal_period": false,
"cart_id": null,
"channel_id": "ch_UkLWZg9DAJ",
"company_id": null,
"company_name": null,
"po_document_filename": null,
"po_document_byte_size": null,
"number": "R1002",
"email": "pinned@example.com",
"customer_note": null,
"po_number": null,
"currency": "USD",
"locale": "en",
"total_quantity": 0,
"coupon_code": null,
"fulfillment_status": null,
"payment_status": null,
"completed_at": null,
"item_total": "0.0",
"display_item_total": "$0.00",
"adjustment_total": "0.0",
"display_adjustment_total": "$0.00",
"discount_total": "0.0",
"display_discount_total": "$0.00",
"tax_total": "0.0",
"display_tax_total": "$0.00",
"included_tax_total": "0.0",
"display_included_tax_total": "$0.00",
"additional_tax_total": "0.0",
"display_additional_tax_total": "$0.00",
"total": "0.0",
"display_total": "$0.00",
"gift_card_total": "0.0",
"display_gift_card_total": "$0.00",
"amount_due": "0.0",
"display_amount_due": "$0.00",
"delivery_total": "0.0",
"display_delivery_total": "$0.00",
"fee_total": "0.0",
"display_fee_total": "$0.00",
"store_credit_total": "0.0",
"display_store_credit_total": "$0.00",
"covered_by_store_credit": false,
"gift_card": null,
"market": {
"id": "mkt_UkLWZg9DAJ",
"name": "United States",
"currency": "USD",
"default_locale": "en",
"tax_inclusive": false,
"default": true,
"country_codes": [
"US"
],
"supported_locales": [
"en"
],
"tax_provider": null,
"created_at": "2026-01-15T12:00:00.000Z",
"updated_at": "2026-01-15T12:00:00.000Z"
},
"external_references": {},
"status": "draft",
"last_ip_address": null,
"considered_risky": false,
"confirmation_delivered": false,
"store_owner_notification_delivered": null,
"payment_total": "0.0",
"display_payment_total": "$0.00",
"metadata": {},
"cancel_note": null,
"commission_amount_total": "0.0",
"display_commission_amount_total": "$0.00",
"commission_tax_total": "0.0",
"display_commission_tax_total": "$0.00",
"commission_total": "0.0",
"display_commission_total": "$0.00",
"canceled_at": null,
"approved_at": null,
"created_at": "2026-01-15T12:00:00.000Z",
"updated_at": "2026-01-15T12:00:00.000Z",
"preferred_stock_location_id": "sloc_UkLWZg9DAJ",
"po_document_url": null,
"seller_id": null,
"order_group_id": null,
"tags": [],
"internal_note": null,
"internal_note_html": null,
"approver_id": null,
"approver_type": null,
"canceler_id": null,
"canceler_type": null,
"created_by_id": "adm_UkLWZg9DAJ",
"created_by_type": "admin_user",
"cancel_reason_id": null,
"cancel_reason_name": null,
"customer_id": null,
"freight_summary": null
}Creates a new draft order in one shot. Customer, items, addresses, currency, market, channel, locale, notes, metadata, and a coupon code can all be provided inline.
Setting preferred_stock_location_id pins the order’s preferred fulfillment
location — Order Routing’s built-in PreferredLocation rule consumes it
when picking which stock location ships each shipment.
Invalid coupon codes are non-fatal — the order is created and the failure is reported on the service result (not in the API response body for now).
Required scope: write_orders (for API-key authentication).
import { createAdminClient } from '@spree/admin-sdk'
const client = createAdminClient({
baseUrl: 'https://your-store.com',
secretKey: 'sk_xxx',
})
// One-shot order create: customer, items, addresses, market, channel,
// notes, metadata, and a coupon code in a single call. Everything
// except `email` is optional.
const order = await client.orders.create({
email: 'jane@example.com',
customer_id: 'cus_UkLWZg9DAJ', // Existing customer; omit for guest orders
use_customer_default_address: false, // true to copy the customer's saved addresses
currency: 'USD',
market_id: 'mkt_UkLWZg9DAJ',
channel_id: 'ch_UkLWZg9DAJ', // Optional — defaults to the store's primary channel
locale: 'en-US',
// Pin the order's preferred fulfillment location. Order Routing's
// built-in PreferredLocation rule ranks this location first when
// it stocks the cart's items; if it doesn't, routing falls back
// to the next rule (Minimize Splits → Default Location).
preferred_stock_location_id: 'sloc_UkLWZg9DAJ',
customer_note: 'Please leave at the front desk.',
// Rich text: send HTML. Reads return this as plain text, plus
// `internal_note_html` with the markup.
internal_note: '<p>VIP customer — handle with care.</p>',
metadata: {
external_reference: 'subscription_invoice_2026_04',
source: 'recurring-engine',
},
// Items: each variant_id + quantity. Optional metadata per line.
items: [
{ variant_id: 'variant_k5nR8xLq', quantity: 2 },
{ variant_id: 'variant_QXyZ12abCD', quantity: 1, metadata: { gift: true } },
],
// Provide addresses inline OR by ID (existing customer addresses).
shipping_address: {
first_name: 'Jane',
last_name: 'Doe',
address1: '350 Fifth Avenue',
address2: 'Floor 42',
city: 'New York',
postal_code: '10118',
country_code: 'US',
state_code: 'NY',
phone: '+1 212 555 1234',
company: 'Acme Inc.',
},
// shipping_address_id: 'addr_UkLWZg9DAJ', // alternative to inline
billing_address: {
first_name: 'Jane',
last_name: 'Doe',
address1: '350 Fifth Avenue',
city: 'New York',
postal_code: '10118',
country_code: 'US',
state_code: 'NY',
phone: '+1 212 555 1234',
},
// billing_address_id: 'addr_UkLWZg9DAJ',
// Optional. Invalid codes are non-fatal — the order is created either way.
coupon_code: 'WELCOME10',
})spree api post /orders -d '{"email":"jane@example.com","customer_id":"cus_UkLWZg9DAJ","use_customer_default_address":false,"currency":"USD","market_id":"mkt_UkLWZg9DAJ","channel_id":"ch_UkLWZg9DAJ","locale":"en-US","preferred_stock_location_id":"sloc_UkLWZg9DAJ","customer_note":"Please leave at the front desk.","internal_note":"<p>VIP customer — handle with care.</p>","metadata":{"external_reference":"subscription_invoice_2026_04","source":"recurring-engine"},"items":[{"variant_id":"variant_k5nR8xLq","quantity":2},{"variant_id":"variant_QXyZ12abCD","quantity":1,"metadata":{"gift":true}}],"shipping_address":{"first_name":"Jane","last_name":"Doe","address1":"350 Fifth Avenue","address2":"Floor 42","city":"New York","postal_code":"10118","country_code":"US","state_code":"NY","phone":"+1 212 555 1234","company":"Acme Inc."},"billing_address":{"first_name":"Jane","last_name":"Doe","address1":"350 Fifth Avenue","city":"New York","postal_code":"10118","country_code":"US","state_code":"NY","phone":"+1 212 555 1234"},"coupon_code":"WELCOME10"}'{
"id": "or_gbHJdmfrXB",
"market_id": "mkt_UkLWZg9DAJ",
"withdrawal_period_ends_at": null,
"within_withdrawal_period": false,
"cart_id": null,
"channel_id": "ch_UkLWZg9DAJ",
"company_id": null,
"company_name": null,
"po_document_filename": null,
"po_document_byte_size": null,
"number": "R1002",
"email": "pinned@example.com",
"customer_note": null,
"po_number": null,
"currency": "USD",
"locale": "en",
"total_quantity": 0,
"coupon_code": null,
"fulfillment_status": null,
"payment_status": null,
"completed_at": null,
"item_total": "0.0",
"display_item_total": "$0.00",
"adjustment_total": "0.0",
"display_adjustment_total": "$0.00",
"discount_total": "0.0",
"display_discount_total": "$0.00",
"tax_total": "0.0",
"display_tax_total": "$0.00",
"included_tax_total": "0.0",
"display_included_tax_total": "$0.00",
"additional_tax_total": "0.0",
"display_additional_tax_total": "$0.00",
"total": "0.0",
"display_total": "$0.00",
"gift_card_total": "0.0",
"display_gift_card_total": "$0.00",
"amount_due": "0.0",
"display_amount_due": "$0.00",
"delivery_total": "0.0",
"display_delivery_total": "$0.00",
"fee_total": "0.0",
"display_fee_total": "$0.00",
"store_credit_total": "0.0",
"display_store_credit_total": "$0.00",
"covered_by_store_credit": false,
"gift_card": null,
"market": {
"id": "mkt_UkLWZg9DAJ",
"name": "United States",
"currency": "USD",
"default_locale": "en",
"tax_inclusive": false,
"default": true,
"country_codes": [
"US"
],
"supported_locales": [
"en"
],
"tax_provider": null,
"created_at": "2026-01-15T12:00:00.000Z",
"updated_at": "2026-01-15T12:00:00.000Z"
},
"external_references": {},
"status": "draft",
"last_ip_address": null,
"considered_risky": false,
"confirmation_delivered": false,
"store_owner_notification_delivered": null,
"payment_total": "0.0",
"display_payment_total": "$0.00",
"metadata": {},
"cancel_note": null,
"commission_amount_total": "0.0",
"display_commission_amount_total": "$0.00",
"commission_tax_total": "0.0",
"display_commission_tax_total": "$0.00",
"commission_total": "0.0",
"display_commission_total": "$0.00",
"canceled_at": null,
"approved_at": null,
"created_at": "2026-01-15T12:00:00.000Z",
"updated_at": "2026-01-15T12:00:00.000Z",
"preferred_stock_location_id": "sloc_UkLWZg9DAJ",
"po_document_url": null,
"seller_id": null,
"order_group_id": null,
"tags": [],
"internal_note": null,
"internal_note_html": null,
"approver_id": null,
"approver_type": null,
"canceler_id": null,
"canceler_type": null,
"created_by_id": "adm_UkLWZg9DAJ",
"created_by_type": "admin_user",
"cancel_reason_id": null,
"cancel_reason_name": null,
"customer_id": null,
"freight_summary": null
}Authorizations
Secret API key for admin access
JWT token for admin user authentication
Headers
Bearer token for admin authentication
Body
"customer@example.com"
Customer ID.
When true with customer_id, copies the customer's saved billing/shipping addresses onto the order.
"USD"
Market ID
Channel ID. Defaults to the store primary channel when omitted.
Stock Location ID to prefer for fulfillment. Order Routing's built-in PreferredLocation rule reads this and ranks the location first; routing falls back to the next rule when the preferred location can't cover the cart.
"en-US"
Public, customer-visible note
Staff-only note
Arbitrary key/value metadata
Show child attributes
Show child attributes
Existing customer address ID
Show child attributes
Show child attributes
Existing customer address ID
Show child attributes
Show child attributes
Optional. Applied non-fatally; invalid codes do not block creation.
Response
order created with preferred_stock_location_id
Was this page helpful?

