Quickstart

A carrier label request timed out. Use the API to check whether it is safe to request another label.

1. Create an API key

Sign in with your email address and the six-digit code RackSort sends you. On your account page, create a named API key and copy it while it is visible.

2. Send the example request

Replace paste-your-key-here with your key. This command sends the sample shipment history and proposed label request to RackSort.

export RACKSORT_API_KEY="paste-your-key-here"
curl https://racksort.com/api/v1/decide \
  -H "Authorization: Bearer $RACKSORT_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'EOF'
{
  "decision": "carrier",
  "proposal": {
    "operation": "LabelCreate",
    "key": "CR-0413",
    "digest": "c7e1f0"
  },
  "connector": {
    "carrier": "UPS",
    "idempotency": "unverified",
    "lookup": "verified"
  },
  "requests": [
    {
      "key": "CR-0412",
      "digest": "c7e1f0",
      "operation": "LabelCreate",
      "attempts": [
        {
          "kind": "request",
          "transport": "sent",
          "at": "2026-10-02T14:02:11Z",
          "evidence": "POST /api/shipments/v2409/ship: read timed out after 30000 ms; request body fully written"
        }
      ]
    }
  ]
}
EOF

3. Read the verdict

The example proposes a new label while the earlier request is still Uncertain. A reconcile verdict means you should look up the earlier request with the carrier before buying another label. next.text gives the instruction, facts records what happened to the earlier request, and clauses identifies the rules behind the verdict.

You can also open the carrier example in the console and select Decide. The console uses your signed-in session.

Use the API from your application

Set RACKSORT_API_KEY in your environment to send the same request from Python or TypeScript.

Python

Python 3.8 or newer, standard library only. Keep the User-Agent header: requests with Python's default one are refused. With requests or httpx it is not needed.

import json
import os
import urllib.error
import urllib.request

request = {
    "decision": "carrier",
    "proposal": {
        "operation": "LabelCreate",
        "key": "CR-0413",
        "digest": "c7e1f0",
    },
    "connector": {
        "carrier": "UPS",
        "idempotency": "unverified",
        "lookup": "verified",
    },
    "requests": [
        {
            "key": "CR-0412",
            "digest": "c7e1f0",
            "operation": "LabelCreate",
            "attempts": [
                {
                    "kind": "request",
                    "transport": "sent",
                    "at": "2026-10-02T14:02:11Z",
                    "evidence": "POST /api/shipments/v2409/ship: read timed out after 30000 ms; request body fully written",
                },
            ],
        },
    ],
}

call = urllib.request.Request(
    "https://racksort.com/api/v1/decide",
    data=json.dumps(request).encode(),
    headers={
        "Authorization": f"Bearer {os.environ['RACKSORT_API_KEY']}",
        "Content-Type": "application/json",
        # Cloudflare refuses Python's default User-Agent, so name the client.
        "User-Agent": "racksort-example/1.0",
    },
)
try:
    with urllib.request.urlopen(call, timeout=30) as response:
        result = json.load(response)
except urllib.error.HTTPError as error:
    raise SystemExit(json.load(error)["error"]["message"])
print(result["verdict"], "-", result["next"]["text"])

TypeScript

Node.js 18 or newer. Save it as decide.mts and run npx tsx decide.mts.

type Verdict = "allow" | "replay" | "reject" | "review" | "reconcile";
interface Decision {
  verdict: Verdict;
  state?: string;
  next: { action: string; text: string; role?: string };
}

const request = {
  "decision": "carrier",
  "proposal": {
    "operation": "LabelCreate",
    "key": "CR-0413",
    "digest": "c7e1f0"
  },
  "connector": {
    "carrier": "UPS",
    "idempotency": "unverified",
    "lookup": "verified"
  },
  "requests": [
    {
      "key": "CR-0412",
      "digest": "c7e1f0",
      "operation": "LabelCreate",
      "attempts": [
        {
          "kind": "request",
          "transport": "sent",
          "at": "2026-10-02T14:02:11Z",
          "evidence": "POST /api/shipments/v2409/ship: read timed out after 30000 ms; request body fully written"
        }
      ]
    }
  ]
};

const response = await fetch("https://racksort.com/api/v1/decide", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.RACKSORT_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(request),
});
const body = await response.json();
if (!response.ok) throw new Error(body.error.message);
const result = body as Decision;
console.log(result.verdict, "-", result.next.text);

Each decision guide includes a worked example with curl, Python and TypeScript code.

HTTP 200 means RackSort reached a verdict. If that verdict is reject, stop the proposed operation. See the API reference for response fields or the error guide if the API returns an error.