API
Carts
Shareable carts that close on WhatsApp
# Carts > Shareable carts that close on WhatsApp - Page: https://tbit.app/docs/api/carts - Base URL: `https://rest-api.tbit.app/v1` - Authentication: `X-API-Key` header with your key on every request (the examples read it from the `TBIT_API_KEY` environment variable) ## Overview Carts let a storefront visitor build a list of products and hand it off to a WhatsApp conversation with full context. A cart is a short-lived snapshot: it gets a 7-character code, is valid for 90 days, and is immutable: to change it, create a new one. ## How the Flow Works 1. A visitor on your storefront builds a list of products. 2. Your storefront creates a cart with POST /v1/carts and gets back a short code. 3. You send the visitor a link like https://<your-storefront>/c/<code> over WhatsApp. 4. When the conversation starts, your agent already has full context of what the visitor picked. ## Endpoints | Method | Path | Description | | --- | --- | --- | | `POST` | `/v1/carts` | Create a shareable cart | | `GET` | `/v1/carts/:code` | Resolve a cart by code | ## Create a Cart Send 1-50 items, each referencing a product id with a qty between 1 and 99. The response is the cart's short code: `POST /v1/carts` ```bash curl -X POST "https://rest-api.tbit.app/v1/carts" \ -H "X-API-Key: $TBIT_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "items": [ { "id": "prod_id_1", "qty": 2 }, { "id": "prod_id_2", "qty": 1 } ] }' ``` Response: ```json { "data": { "code": "K3F9X2A" } } ``` ## Get a Cart Resolve a code back into its items, each one a full product object plus qty. Carts are tenant-isolated: a key only resolves carts created for its own agent: anything else returns 404: `GET /v1/carts/K3F9X2A` ```bash curl "https://rest-api.tbit.app/v1/carts/K3F9X2A" \ -H "X-API-Key: $TBIT_API_KEY" ``` Response: ```json { "data": { "code": "K3F9X2A", "created_at": "2024-09-01T12:00:00Z", "items": [ { "_id": "prod_id_1", "kind": "product", "title": "Kit fiesta dinosaurios", "currency": "COP", "base_price": 95000, "qty": 2 }, { "_id": "prod_id_2", "kind": "product", "title": "Piñata dinosaurio", "currency": "COP", "base_price": 45000, "qty": 1 } ] } } ``` ## Notes - Codes are 7 characters long. - Carts are valid for 90 days. - Carts are immutable: create a new one to change the items. - Carts from other agents (or unknown codes) return 404.Carts let a storefront visitor build a list of products and hand it off to a WhatsApp conversation with full context. A cart is a short-lived snapshot: it gets a 7-character code, is valid for 90 days, and is immutable: to change it, create a new one.
- A visitor on your storefront builds a list of products.
- Your storefront creates a cart with POST /v1/carts and gets back a short code.
- You send the visitor a link like https://<your-storefront>/c/<code> over WhatsApp.
- When the conversation starts, your agent already has full context of what the visitor picked.
| Method | Path | Description |
|---|---|---|
| POST | /v1/carts | Create a shareable cart |
| GET | /v1/carts/:code | Resolve a cart by code |
Send 1-50 items, each referencing a product id with a qty between 1 and 99. The response is the cart's short code:
/v1/cartscurl -X POST "https://rest-api.tbit.app/v1/carts" \
-H "X-API-Key: $TBIT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"items": [
{
"id": "prod_id_1",
"qty": 2
},
{
"id": "prod_id_2",
"qty": 1
}
]
}'const response = await fetch('https://rest-api.tbit.app/v1/carts', {
method: 'POST',
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
items: [
{
id: 'prod_id_1',
qty: 2,
},
{
id: 'prod_id_2',
qty: 1,
},
],
}),
});
const data = await response.json();import axios from 'axios';
const { data } = await axios.post(
'https://rest-api.tbit.app/v1/carts',
{
items: [
{
id: 'prod_id_1',
qty: 2,
},
{
id: 'prod_id_2',
qty: 1,
},
],
},
{
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
},
},
);import os
import requests
response = requests.post(
'https://rest-api.tbit.app/v1/carts',
headers={'X-API-Key': os.environ['TBIT_API_KEY']},
json={
'items': [
{
'id': 'prod_id_1',
'qty': 2,
},
{
'id': 'prod_id_2',
'qty': 1,
},
],
},
)
data = response.json()<?php
$ch = curl_init('https://rest-api.tbit.app/v1/carts');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . getenv('TBIT_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'items' => [
[
'id' => 'prod_id_1',
'qty' => 2,
],
[
'id' => 'prod_id_2',
'qty' => 1,
],
],
]),
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);{
"data": {
"code": "K3F9X2A"
}
}Resolve a code back into its items, each one a full product object plus qty. Carts are tenant-isolated: a key only resolves carts created for its own agent: anything else returns 404:
/v1/carts/K3F9X2Acurl "https://rest-api.tbit.app/v1/carts/K3F9X2A" \
-H "X-API-Key: $TBIT_API_KEY"const response = await fetch('https://rest-api.tbit.app/v1/carts/K3F9X2A', {
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
},
});
const data = await response.json();import axios from 'axios';
const { data } = await axios.get(
'https://rest-api.tbit.app/v1/carts/K3F9X2A',
{
headers: {
'X-API-Key': process.env.TBIT_API_KEY,
},
},
);import os
import requests
response = requests.get(
'https://rest-api.tbit.app/v1/carts/K3F9X2A',
headers={'X-API-Key': os.environ['TBIT_API_KEY']},
)
data = response.json()<?php
$ch = curl_init('https://rest-api.tbit.app/v1/carts/K3F9X2A');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . getenv('TBIT_API_KEY'),
],
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);{
"data": {
"code": "K3F9X2A",
"created_at": "2024-09-01T12:00:00Z",
"items": [
{
"_id": "prod_id_1",
"kind": "product",
"title": "Kit fiesta dinosaurios",
"currency": "COP",
"base_price": 95000,
"qty": 2
},
{
"_id": "prod_id_2",
"kind": "product",
"title": "Piñata dinosaurio",
"currency": "COP",
"base_price": 45000,
"qty": 1
}
]
}
}- Codes are 7 characters long.
- Carts are valid for 90 days.
- Carts are immutable: create a new one to change the items.
- Carts from other agents (or unknown codes) return 404.