Getting Started
This guide will help you make your first API call to OK Capsule.
Full API Reference
Response examples are simplified. See the Interactive API Documentation for complete response schemas.
Prerequisites
- API credentials (contact your OK Capsule account representative)
- An HTTP client of your choice
Step 1: Authentication
OK Capsule uses OAuth 2.0 for authentication. First, obtain an access token:
- TypeScript
- cURL
const response = await fetch("https://na1-prod.okcapsule.app/v2/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
email: "your-email@example.com",
password: "your-password",
}),
});
const { access_token, refresh_token } = await response.json();
curl -X POST https://na1-prod.okcapsule.app/v2/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "your-email@example.com",
"password": "your-password"
}'
Response:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refresh_token": "dGhpcyBpcyBhIHJlZnJlc2ggdG9rZW4...",
"expires_in": 86400
}
Token Expiration
Access tokens expire after 24 hours. Use the refresh token to obtain a new access token without re-authenticating.
Step 2: Make Your First Request
Use the access token to make authenticated requests. Let's fetch your client products:
- TypeScript
- cURL
const response = await fetch(
"https://na1-prod.okcapsule.app/v2/client-products",
{
headers: {
Authorization: `Bearer ${access_token}`,
},
}
);
const { client_products } = await response.json();
curl -X GET https://na1-prod.okcapsule.app/v2/client-products \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Response:
{
"client_products": [
{
"id": "d290f1ee-6c54-4b01-90e6-d701748f0851",
"product_name": "Vitamin D3",
"active": true,
"serving_size": 1
}
]
}
Step 3: Create Your First Order
Now let's create a simple order:
- TypeScript
- cURL
const order = {
consumer: {
first_name: "John",
last_name: "Doe",
email: "john.doe@example.com",
},
shipping_address: {
address1: "742 Evergreen Terrace",
city: "Springfield",
province_name: "Illinois",
country_name: "United States",
postal_code: "62701",
},
order_lines: [
{
duration: 30,
pouches: [
{
time_of_administration: "Morning",
contents: [
{
client_product_id: "d290f1ee-6c54-4b01-90e6-d701748f0851",
serving_size: 1,
},
],
},
],
},
],
};
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: createdOrder } = await response.json();
curl -X POST https://na1-prod.okcapsule.app/v2/orders \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"consumer": {
"first_name": "John",
"last_name": "Doe",
"email": "john.doe@example.com"
},
"shipping_address": {
"address1": "742 Evergreen Terrace",
"city": "Springfield",
"province_name": "Illinois",
"country_name": "United States",
"postal_code": "62701"
},
"order_lines": [
{
"duration": 30,
"pouches": [
{
"time_of_administration": "Morning",
"contents": [
{
"client_product_id": "d290f1ee-6c54-4b01-90e6-d701748f0851",
"serving_size": 1
}
]
}
]
}
]
}'
Response:
{
"order": {
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"status": "Pending",
"consumer": {
"id": "f1e2d3c4-b5a6-7890-1234-567890abcdef",
"first_name": "John",
"last_name": "Doe"
}
}
}
Next Steps
- Create Orders - Learn different order creation patterns
- Manage Consumers - Create and update consumers
- Track Fulfillments - Monitor shipping and delivery
API Reference
For complete endpoint documentation, visit the Interactive API Documentation.