Manage Consumers
Consumers are the end customers who receive supplement orders.
Full API Reference
Response examples are simplified. See the complete endpoint documentation for the full response schema.
Create a Consumer
- TypeScript
- cURL
const consumer = {
email: "john.doe@example.com",
first_name: "John",
last_name: "Doe",
phone_number: "+12133734253",
client_custom_consumer_id: "CUST-12345",
};
const response = await fetch("https://na1-prod.okcapsule.app/v2/consumers", {
method: "POST",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
body: JSON.stringify(consumer),
});
const { consumer: created } = await response.json();
curl -X POST https://na1-prod.okcapsule.app/v2/consumers \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"email": "john.doe@example.com",
"first_name": "John",
"last_name": "Doe",
"phone_number": "+12133734253",
"client_custom_consumer_id": "CUST-12345"
}'
Response:
{
"consumer": {
"id": "d290f1ee-6c54-4b01-90e6-d701748f0851",
"client_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"email": "john.doe@example.com",
"first_name": "John",
"last_name": "Doe",
"phone_number": "+12133734253",
"client_custom_consumer_id": "CUST-12345",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z"
}
}
Required Fields
| Field | Max Length |
|---|---|
email | 100 |
first_name | 100 |
last_name | 100 |
Optional Fields
| Field | Max Length | Notes |
|---|---|---|
phone_number | 15 | E.164 format recommended |
client_custom_consumer_id | - | Your internal customer ID |
Get a Consumer
- TypeScript
- cURL
const response = await fetch(
`https://na1-prod.okcapsule.app/v2/consumers/${consumerId}`,
{
headers: { Authorization: `Bearer ${access_token}` },
}
);
const { consumer } = await response.json();
curl -X GET https://na1-prod.okcapsule.app/v2/consumers/{id} \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
List Consumers
- TypeScript
- cURL
const response = await fetch(
"https://na1-prod.okcapsule.app/v2/consumers?limit=20",
{
headers: { Authorization: `Bearer ${access_token}` },
}
);
const { consumers } = await response.json();
curl -X GET "https://na1-prod.okcapsule.app/v2/consumers?limit=20" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Query Parameters
| Parameter | Description |
|---|---|
limit | Number of results (default: 20, max: 100) |
cursor | Pagination cursor for next page |
Update a Consumer
- TypeScript
- cURL
const response = await fetch(
`https://na1-prod.okcapsule.app/v2/consumers/${consumerId}`,
{
method: "PUT",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
first_name: "Jonathan",
phone_number: "+12135551234",
}),
}
);
const { consumer } = await response.json();
curl -X PUT https://na1-prod.okcapsule.app/v2/consumers/{id} \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"first_name": "Jonathan",
"phone_number": "+12135551234"
}'
Only include fields you want to update.
Consumer Addresses
Consumers can have multiple addresses.
Add an Address
- TypeScript
- cURL
const address = {
is_default: true,
address_type: "shipping",
addressed_to: "John Doe",
address1: "742 Evergreen Terrace",
address2: "Apt 2B",
city: "Springfield",
province_name: "Illinois",
country_name: "United States",
postal_code: "62701",
phone_number: "+12175551234",
};
const response = await fetch(
`https://na1-prod.okcapsule.app/v2/consumers/${consumerId}/addresses`,
{
method: "POST",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
body: JSON.stringify(address),
}
);
const { address: created } = await response.json();
curl -X POST https://na1-prod.okcapsule.app/v2/consumers/{consumerId}/addresses \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"is_default": true,
"address_type": "shipping",
"addressed_to": "John Doe",
"address1": "742 Evergreen Terrace",
"address2": "Apt 2B",
"city": "Springfield",
"province_name": "Illinois",
"country_name": "United States",
"postal_code": "62701",
"phone_number": "+12175551234"
}'
Address Field Constraints
| Field | Max Length |
|---|---|
addressed_to | 35 |
address1 | 100 |
address2 | 100 |
city | 50 |
province_name | 30 |
postal_code | 10 |
phone_number | 15 |
Address Types
shipping- Delivery addressbilling- Billing addressreturn- Return address (requires phone number)
List Consumer Addresses
GET /v2/consumers/{consumerId}/addresses
Update an Address
PUT /v2/consumers/{consumerId}/addresses/{addressId}
Inline Consumer Creation
When creating orders, you can create consumers inline:
{
"consumer": {
"first_name": "John",
"last_name": "Doe",
"email": "john.doe@example.com"
},
"shipping_address": { ... },
"order_lines": [ ... ]
}
The consumer is created automatically if no matching email exists.
Best Practices
Use client_custom_consumer_id
Store your internal customer ID in client_custom_consumer_id to easily correlate consumers between systems.