Skip to main content

Create Orders

This guide covers common order creation patterns.

Full API Reference

Response examples are simplified. See the complete endpoint documentation for the full response schema.

Minimal Order Example

The absolute minimum order payload:

{
"consumer": {
"first_name": "John",
"last_name": "Doe"
},
"shipping_address": {
"address1": "123 Main St",
"city": "Springfield",
"country_name": "United States"
},
"order_lines": [
{
"pouches": [
{
"contents": [{ "client_product_id": "YOUR-PRODUCT-UUID-HERE" }]
}
]
}
]
}
Get Your Product ID First

Before creating an order, list your products to get valid IDs:

curl -X GET https://na1-prod.okcapsule.app/v2/products \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Use an id from the response in client_product_id.

Required Fields

Every order requires:

  • consumer - Who receives the order (new or existing)
  • shipping_address - Where to ship
  • order_lines - What to include (pouches with contents)
Consumer: ID or name, never both

The consumer object must contain either an id (existing consumer) or both first_name and last_name (new consumer). Mixing the two — for example, passing id together with first_name — is rejected.

Order Line Types

Each order_line is one of three types. The shape of the order line (and its pouches) tells the API which type you're sending — there is no type field.

Custom Pack

Client defines which supplements go into each pouch. Requires pouches[] with contents[]. Must not include standalone_id.

{
"order_lines": [
{
"duration": 30,
"pouches": [
{
"time_of_administration": "Morning",
"contents": [
{ "client_product_id": "vitamin-d3-uuid", "serving_size": 2 },
{ "client_product_id": "magnesium-uuid", "serving_size": 1 }
]
}
]
}
]
}

Curated Pack

A pouch sourced from a pre-defined assembly instead of inline ingredients. The pouch references pack_id and omits contents. The order line still uses pouches[] (see Example 3 for the full example).

{
"order_lines": [
{
"pouches": [
{
"pack_id": "f1e2d3c4-b5a6-7890-1234-567890abcdef",
"time_of_administration": "Morning"
}
]
}
]
}
tip

A pouch must specify either pack_id or contents, not both.

Standalone

A single non-pouched product (e.g. a bottle or a single SKU). Requires standalone_id and quantity (integer ≥ 1). Must not include pouches.

{
"order_lines": [
{
"standalone_id": "a9b8c7d6-e5f4-3210-9876-543210fedcba",
"quantity": 2
}
]
}

A single order can mix types — include one order line per pack or standalone product.

Example 1: New Consumer

Create an order for a new consumer by providing their details inline:

const order = {
consumer: {
first_name: "John",
last_name: "Doe",
email: "john.doe@example.com",
phone_number: "+12133734253",
},
shipping_address: {
address1: "742 Evergreen Terrace",
city: "Springfield",
province_name: "Illinois",
country_name: "United States",
postal_code: "62701",
},
order_lines: [
{
pouches: [
{
time_of_administration: "Morning",
contents: [
{
client_product_id: "d290f1ee-6c54-4b01-90e6-d701748f0851",
serving_size: 2,
},
],
},
],
},
],
};

const response = await fetch("https://na1-prod.okcapsule.app/v2/orders", {
method: "POST",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
body: JSON.stringify(order),
});

const { order: created } = await response.json();

The consumer will be created automatically and the ID returned in the response.

Example 2: Existing Consumer

Reference an existing consumer by ID:

const order = {
consumer: {
id: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
},
shipping_address: {
address1: "742 Evergreen Terrace",
city: "Springfield",
country_name: "United States",
},
order_lines: [
{
pouches: [
{
contents: [
{ client_product_id: "d290f1ee-6c54-4b01-90e6-d701748f0851" },
],
},
],
},
],
};

const response = await fetch("https://na1-prod.okcapsule.app/v2/orders", {
method: "POST",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
body: JSON.stringify(order),
});

Example 3: Using an Assembly (Pre-built Pack)

Use a pre-configured assembly instead of specifying contents:

const order = {
consumer: {
first_name: "John",
last_name: "Doe",
},
shipping_address: {
address1: "742 Evergreen Terrace",
city: "Springfield",
country_name: "United States",
},
order_lines: [
{
pouches: [
{
pack_id: "f1e2d3c4-b5a6-7890-1234-567890abcdef",
time_of_administration: "Morning",
},
],
},
],
};
tip

When using pack_id, you cannot also specify contents. Choose one or the other.

Example 4: Multiple Times of Administration

Create pouches for different times of day:

const order = {
consumer: {
first_name: "John",
last_name: "Doe",
},
shipping_address: {
address1: "742 Evergreen Terrace",
city: "Springfield",
country_name: "United States",
},
order_lines: [
{
duration: 30,
pouches: [
{
time_of_administration: "Morning",
custom_label: "AM Vitamins",
contents: [
{ client_product_id: "product-1-uuid", serving_size: 2 },
{ client_product_id: "product-2-uuid", serving_size: 1 },
],
},
{
time_of_administration: "Evening",
custom_label: "PM Vitamins",
contents: [{ client_product_id: "product-3-uuid", serving_size: 1 }],
},
],
},
],
};

Example 5: Common Optional Fields

{
"consumer": {
"first_name": "John",
"last_name": "Doe",
"email": "john.doe@example.com",
"phone_number": "+12133734253"
},
"shipping_address": {
"addressee": "John Doe",
"address1": "742 Evergreen Terrace",
"address2": "Apt 2B",
"city": "Springfield",
"province_name": "Illinois",
"country_name": "United States",
"postal_code": "62701"
},
"source": "Shopify",
"source_client_order_id": "ORD-2024-001",
"order_type": "DTC",
"order_lines": [
{
"name": "Monthly Wellness Pack",
"physician_name": "Dr. Smith",
"duration": 30,
"is_expedited": false,
"pouches": [
{
"time_of_administration": "Morning",
"custom_label": "AM Vitamins",
"cycle": "daily",
"cycle_length": 7,
"contents": [
{ "client_product_id": "product-1-uuid", "serving_size": 2 },
{ "client_product_id": "product-2-uuid", "serving_size": 1 }
]
}
]
}
]
}

Field Constraints

FieldMax LengthNotes
consumer.first_name100
consumer.last_name100
consumer.email100
consumer.phone_number30Typically an E.164 number (+12133734253). Extensions are accepted (+12107284548ext12733). Formatted numbers like (213) 373-4253 are not validated by the API but should be avoided since they aren't normalized before being passed to carriers.
shipping_address.addressee200Defaults to consumer name
shipping_address.address1100
shipping_address.address2100
shipping_address.city50
order_line.physician_name30
pouch.custom_label30Alphanumeric + common symbols
order_line.duration1-60Days. Defaults to 30 when omitted.

Less Common Optional Fields

FieldLevelDefaultNotes
pouch.cyclepouch"daily"Cycle marker for the pouch.
pouch.cycle_lengthpouch7Days the cycle repeats. Allowed values: 0, 7, 10.
order_line.is_priority_shippingorder_linefalsePriority shipping flag (separate from is_expedited).
order_line.is_priority_productionorder_linefalsePriority production flag.
order_line.lot_informationorder_linenullFree-text traceability string.

Validation Rules

Pouch Limits
  • Maximum 8 supplements per pouch
  • Orders are rejected if pouch count exceeds dispenser box capacity
Time of Administration

Common values: Morning, Midday, Evening. The API accepts other values, but only these three are supported across the rest of the platform — contact your OKC representative before using anything else.

Error Handling

Common validation errors:

ErrorCause
consumer.last_name is requiredProviding first_name requires last_name
Either pack_id or contents requiredPouch needs one or the other
Invalid client_product_idProduct doesn't exist or isn't active

See Also