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.
Required Fields
Every order requires:
consumer- Who receives the order (new or existing)shipping_address- Where to shiporder_lines- What to include (pouches with contents)
Pattern 1: New Consumer
Create an order for a new consumer by providing their details inline:
- TypeScript
- JSON Payload
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();
{
"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
}
]
}
]
}
]
}
The consumer will be created automatically and the ID returned in the response.
Pattern 2: Existing Consumer
Reference an existing consumer by ID:
- TypeScript
- JSON Payload
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),
});
{
"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" }
]
}
]
}
]
}
Pattern 3: Using an Assembly (Pre-built Pack)
Use a pre-configured assembly instead of specifying contents:
- TypeScript
- JSON Payload
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",
},
],
},
],
};
{
"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.
Pattern 4: Multiple Times of Administration
Create pouches for different times of day:
- TypeScript
- JSON Payload
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 }],
},
],
},
],
};
{
"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 }
]
}
]
}
]
}
Pattern 5: Complete Order with All Options
- JSON Payload
{
"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
| Field | Max Length | Notes |
|---|---|---|
consumer.first_name | 100 | |
consumer.last_name | 100 | |
consumer.email | 100 | |
consumer.phone_number | 15 | E.164 format |
shipping_address.addressee | 200 | Defaults to consumer name |
shipping_address.address1 | 100 | |
shipping_address.address2 | 100 | |
shipping_address.city | 50 | |
order_line.physician_name | 30 | |
pouch.custom_label | 30 | Alphanumeric + common symbols |
order_line.duration | 1-60 | Days |
Validation Rules
Pouch Limits
- Maximum 8 supplements per pouch
- Orders are rejected if pouch count exceeds dispenser box capacity
Time of Administration
Valid values: Morning, Midday, Evening
Error Handling
Common validation errors:
| Error | Cause |
|---|---|
consumer.last_name is required | Providing first_name requires last_name |
Either pack_id or contents required | Pouch needs one or the other |
Invalid client_product_id | Product doesn't exist or isn't active |