Skip to content
Menu

Search the site

Type to search guides, blog, API and product.

↑ ↓ to move · Enter to open · Esc to close

API Reference

API

Carts

Shareable carts that close on WhatsApp

View as Markdown

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.

  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.
MethodPathDescription
POST/v1/cartsCreate a shareable cart
GET/v1/carts/:codeResolve 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
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
      }
    ]
  }'
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);
Response
{
  "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
curl "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);
Response
{
  "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.