border.bot
Esc
  • Loading…
↑ ↓ to move↵ to openEsc to close
Docs menu

Quickstart

Create a border.bot API client, get an access token, classify a product, then calculate its landed cost, with curl.

1. Create an API client#

Sign in to the dashboard and open Developers → API clients. Create a client for your workspace. You get a client ID, a client secret and the token URL. The secret is shown once, so put it in your secrets manager straight away.

bash
export BORDERBOT_TOKEN_URL=https://api.border.bot/oauth2/token
export BORDERBOT_CLIENT_ID=client_...
export BORDERBOT_CLIENT_SECRET=...

Trade them for an access token. It lasts about an hour (expires_in), so fetch a new one before it runs out or after a 401:

bash
export BORDERBOT_TOKEN=$(curl -s -X POST "$BORDERBOT_TOKEN_URL" \
  -d grant_type=client_credentials \
  -d client_id="$BORDERBOT_CLIENT_ID" \
  -d client_secret="$BORDERBOT_CLIENT_SECRET" | jq -r .access_token)

Check the token works. GET /v1/me is free and returns the workspace, the API client and its scopes, and the credit balance:

cURL
curl https://api.border.bot/v1/me \
  -H "Authorization: Bearer $BORDERBOT_TOKEN"

2. Classify a product#

Send a description or a product URL with the destination country. Add the origin if you know it.

cURL
curl -X POST https://api.border.bot/v1/classify \
  -H "Authorization: Bearer $BORDERBOT_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "description": "Men'\''s cotton crew-neck t-shirt, knitted",
    "destinationCountry": "US",
    "originCountry": "PT"
  }'
JavaScript
const response = await fetch('https://api.border.bot/v1/classify', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.BORDERBOT_TOKEN}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': crypto.randomUUID(),
  },
  body: JSON.stringify({
    "description": "Men's cotton crew-neck t-shirt, knitted",
    "destinationCountry": "US",
    "originCountry": "PT"
  }),
});
const data = await response.json();
Python
import os, uuid

import requests

response = requests.post(
    "https://api.border.bot/v1/classify",
    headers={"Authorization": f"Bearer {os.environ['BORDERBOT_TOKEN']}", "Idempotency-Key": str(uuid.uuid4())},
    json={
        "description": "Men's cotton crew-neck t-shirt, knitted",
        "destinationCountry": "US",
        "originCountry": "PT",
    },
)
data = response.json()
PHP
<?php
$ch = curl_init('https://api.border.bot/v1/classify');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('BORDERBOT_TOKEN'),
        'Content-Type: application/json',
        'Idempotency-Key: ' . bin2hex(random_bytes(16)),
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'description' => 'Men\'s cotton crew-neck t-shirt, knitted',
        'destinationCountry' => 'US',
        'originCountry' => 'PT',
    ]),
]);
$data = json_decode(curl_exec($ch), true);

The response has the code in the destination's format, the official description at each level, a confidence score, the reasoning and alternatives. The X-Credits-Charged and X-Credits-Remaining headers say what the call cost.

3. Calculate landed cost#

Pass the code, the origin and destination, the goods value and the shipping cost:

curl -X POST https://api.border.bot/v1/calculate \
  -H "Authorization: Bearer $BORDERBOT_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "hsCode": "6109.10.00.12",
    "originCountry": "PT",
    "destinationCountry": "US",
    "value": 120,
    "currency": "USD",
    "shippingCost": 15
  }'

You get every duty, tax and fee line with its legal basis and the total landed cost. The reference for this endpoint lists every field, including shipping terms, preferential rates and seller-collected taxes.

Next#

Last updated