Developers

The CFX Delivery API

Quote, book and track deliveries from your own system. Start in the sandbox in minutes: no approval needed, nothing is collected or charged.

Quick start

  1. Open a business account at charlesfreightx.co.za. You can use the sandbox straight away; live keys need your account to be approved.
  2. Create a sandbox key in the business portal under API keys. It starts with cfx_test_ and is shown once.
  3. Check it works:
curl https://charlesfreightx.co.za/api/v1/ping \
  -H "Authorization: Bearer $CFX_KEY"
{"ok": true, "mode": "test", "business": "Acme Online", "time": "2026-11-13T09:15:40+02:00"}
  1. Quote, book and follow an order with the requests below, then move the sandbox order along to see your webhooks arrive.

Basics

Base addresshttps://charlesfreightx.co.za/api/v1
AuthenticationAuthorization: Bearer <your key> on every request. HTTPS only.
FormatJSON in, JSON out. Send Content-Type: application/json with a body.
MoneySouth African rand, as numbers with two decimals at most (70, 52.5).
AddressesSend full addresses as text, house number first ("12 Main Road, Dawn Park, Boksburg"). CFX works out the road distance itself; any distance you send is ignored.
DuplicatesSend an Idempotency-Key header (up to 100 characters) or an external_ref when placing orders. Repeating the same request returns the first order instead of making a second one (keys are kept for 24 hours).
Rate limit120 requests a minute per key. Above that you get 429 with Retry-After: 60.
Request idEvery response has an X-Request-Id header. Quote it when you contact us.

Sandbox

Sandbox keys (cfx_test_…) use the same address and the same requests as live keys. Quotes are priced exactly like live, and orders are checked the same way, but sandbox orders are pretend: no driver, no balance used, no e-mails to anyone. They get references like TEST-000001 and carry "sandbox": true.

A sandbox order stays where it is until you move it on, so you can test each webhook:

curl -X POST https://charlesfreightx.co.za/api/v1/test/orders/TEST-000001/advance \
  -H "Authorization: Bearer $CFX_TEST_KEY"

Each call moves it one step: confirmed → ready_for_collection → out_for_delivery → completed. To test a failed delivery send {"to":"delivery_failed"}. Each step sends the normal order.status_changed webhook, with "test": true.

POST /test/webhook sends a signed webhook.test message to your webhook address. Live keys cannot use /test, sandbox keys never see live orders, and live keys never see sandbox orders.

Quote a delivery

POST/quote

Prices a delivery without booking it. Use it at your checkout.

curl -X POST https://charlesfreightx.co.za/api/v1/quote \
  -H "Authorization: Bearer $CFX_KEY" -H "Content-Type: application/json" \
  -d '{
    "pickup": "1 Pickup St, Boksburg",
    "dropoff": "2 Drop Rd, Kempton Park",
    "packages": [{"size": "small", "qty": 1, "weight_kg": 2}],
    "items": [{"desc": "Kettle", "value": 450}],
    "prohibited_ok": true
  }'
{
  "total": 70,
  "lines": [{"label": "Fare", "amount": 67.2}, {"label": "Booking fee", "amount": 2.8}],
  "chargeable_km": 15,
  "total_weight_kg": 2,
  "requires_quote": false,
  "adjustments": [],
  "delivery_service": "STANDARD",
  "handling_service": "STANDARD_HANDLING",
  "plan": "growth"
}
FieldWhat to send
pickup, dropoffRequired. Full addresses with the house or building number.
packagesThe physical parcels: size (small, medium, large, xlarge), qty, and if you have them weight_kg, length_cm, width_cm, height_cm. A heavy parcel is moved up a size automatically and listed in adjustments. One parcel can weigh up to 180 kg.
total_weight_kgOptional if every package has a weight.
itemsRequired. What is inside: desc and declared value in rand per line. No single item may be worth more than R65,000.
prohibited_okRequired, true: you confirm nothing is on the prohibited goods list.
delivery_date, delivery_windowOptional. A date (2026-11-30) and a window code (morning or afternoon).

If requires_quote is true, the delivery is outside what can be booked online (for example a very large load); contact us for a quote.

Place an order

POST/orders

The same fields as a quote, plus who receives it. The order is paid from your prepaid CFX balance; if the balance is too low you get 402 insufficient_balance and nothing is booked.

curl -X POST https://charlesfreightx.co.za/api/v1/orders \
  -H "Authorization: Bearer $CFX_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1001" \
  -d '{
    "pickup": "1 Pickup St, Boksburg",
    "dropoff": "2 Drop Rd, Kempton Park",
    "recipient": "Thandi Mokoena",
    "recipient_phone": "+27821234567",
    "recipient_email": "thandi@example.com",
    "packages": [{"size": "small", "qty": 1, "weight_kg": 2}],
    "items": [{"desc": "Kettle", "value": 450}],
    "prohibited_ok": true,
    "external_ref": "SHOP-1001"
  }'

201 Created (or 200 when it is a repeat of an earlier request):

{
  "ref": "CFX-100245",
  "external_ref": "SHOP-1001",
  "status": "confirmed",
  "created_at": "2026-11-13T09:15:40+02:00",
  "pickup": "1 Pickup St, Boksburg",
  "dropoff": "2 Drop Rd, Kempton Park",
  "recipient": "Thandi Mokoena",
  "packages": 1,
  "total": 70,
  "pricing": {"total": 70, "lines": [{"label": "Fare", "amount": 67.2}, {"label": "Booking fee", "amount": 2.8}]},
  "waybill": "CFX-AB23CDE",
  "tracking_token": "q8w2…",
  "payment": {"status": "paid", "amount_paid": 70}
}
Extra fieldWhat to send
recipientRequired. The person receiving the delivery.
recipient_phone, recipient_emailStrongly advised. The recipient gets the tracking link by e-mail, and the driver can call them.
external_refYour own order number. Shown on the waybill and in every webhook.
collection_dateOptional. When the parcels are ready (2026-11-14).
order_kinddelivery (default) or return (collect from your customer, deliver to you).

The tracking_token opens your customer's tracking page: https://charlesfreightx.co.za/ops/track/?t=<token>.

Read orders

GET/orders/{ref}

One order, in the same shape as above.

GET/orders?status=&limit=&before=

Your orders, newest first: {"orders": [ … ]}. limit up to 100 (default 25); before is a date-time for paging.

StatusMeaning
awaiting_paymentWaiting for payment (orders paid outside your balance).
confirmedBooked and paid. Waiting for the parcels to be ready.
ready_for_collectionReady; a driver will collect.
out_for_deliveryCollected and on the way.
partly_deliveredSome parcels of a multi-parcel order are delivered.
delivery_failedThe delivery could not be completed (for example nobody home). You can ask for a rebooking.
completedDelivered, with PIN, signature and photo.
cancelledCancelled before collection.

Ready, cancel, waybill

POST/orders/{ref}/ready

Tell us the parcels are packed and ready for collection.

POST/orders/{ref}/cancel

Cancel before collection. Body (optional): {"reason": "Customer changed their mind"}. After collection you get 409 conflict.

GET/orders/{ref}/waybill

The data for the waybill label (reference, barcode values, recipient and parcels), for printing on your own labels.

POST/deliveries/{ref}/rebook

Ask for a failed delivery to be tried again. Body (optional): {"reason": "…"}. A new delivery fee applies.

Manifest and invoices

GET/manifest?date=2026-11-14

Everything to be collected from you on that day: hand it to your packing team.

GET/invoices?from=2026-11-01&to=2026-11-30

Your paid invoices in that period.

Webhooks

Set an https address in the business portal under Webhooks. CFX sends a POST each time an order changes status. You get a signing secret once; keep it on your server.

POST /your-webhook-address
Content-Type: application/json
X-CFX-Event-Id: 1287
X-CFX-Event-Type: order.status_changed
X-CFX-Signature: t=1763018140,v1=5f2b…

{
  "id": 1287,
  "type": "order.status_changed",
  "created_at": "2026-11-13T09:15:40+02:00",
  "data": {
    "ref": "CFX-100245",
    "external_ref": "SHOP-1001",
    "status": "out_for_delivery",
    "previous_status": "ready_for_collection",
    "waybill": "CFX-AB23CDE",
    "tracking_token": "q8w2…"
  }
}

Events: order.status_changed and webhook.test. Messages hold references and statuses only: no prices and no customer details.

Check the signature

Compute HMAC-SHA256 of t + "." + raw body with your signing secret, as hex, and compare it with v1. Reject messages where t is more than 5 minutes old.

// Node.js (Express: use express.raw() so you get the exact bytes)
const crypto = require('crypto');
function cfxVerify(rawBody, header, secret) {
  const p = Object.fromEntries(header.split(',').map(x => x.split('=')));
  if (Math.abs(Date.now() / 1000 - Number(p.t)) > 300) return false;
  const expect = crypto.createHmac('sha256', secret).update(p.t + '.' + rawBody).digest('hex');
  return crypto.timingSafeEqual(Buffer.from(expect), Buffer.from(p.v1 || ''));
}
<?php // PHP
function cfx_verify($raw, $header, $secret) {
  parse_str(str_replace(',', '&', $header), $p);
  if (abs(time() - (int)$p['t']) > 300) return false;
  return hash_equals(hash_hmac('sha256', $p['t'] . '.' . $raw, $secret), $p['v1'] ?? '');
}
# Python
import hmac, hashlib, time
def cfx_verify(raw: bytes, header: str, secret: str) -> bool:
    p = dict(x.split('=', 1) for x in header.split(','))
    if abs(time.time() - int(p['t'])) > 300: return False
    expect = hmac.new(secret.encode(), p['t'].encode() + b'.' + raw, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expect, p.get('v1', ''))

Answer quickly, expect repeats

Reply with any 2xx within 10 seconds, then do your work. If we get no 2xx we try again after 2, 4, 8, 16 and 32 minutes, six tries in all. Use X-CFX-Event-Id to ignore a message you already handled. You can see every attempt under Webhooks in the portal, and send yourself a test with Send test webhook.

Errors

Errors always look like this, with a message you can show to a person:

{"error": {"code": "invalid_request", "message": "We cannot deliver a single item worth more than R65,000. This one is declared at R70000"}}
HTTPcodeWhat to do
400bad_json, bad_date, bad_status, bad_limit, bad_beforeFix the request.
401invalid_api_keyCheck the key and the Bearer header. A sandbox key only works in the sandbox.
402insufficient_balanceTop up your CFX balance, then send the order again.
403sandbox_onlyThe /test requests need a sandbox key.
404not_found, no_such_endpointCheck the reference or the address.
409idempotency_conflict, conflictThe key was used for a different order, or the order can no longer change.
413too_largeKeep requests under 100 KB.
422invalid_request, address_not_found, not_in_sandboxShow the message to the person; they can fix it.
429rate_limitedWait 60 seconds.
5xxserver_error, upstream_unavailable, distance_unavailableTry again shortly with the same Idempotency-Key: you will never get a duplicate.

Shopify

  1. In the CFX business portal open Shopify / WooCommerce, save your collection address and copy the Shopify address.
  2. In Shopify: Settings › Notifications › Webhooks › Create webhook. Event Order creation, format JSON, paste the address.
  3. Shopify shows a signing secret under the webhook list. Paste it into the portal as the Shopify signing secret and save.
  4. Place a test order in your store. It appears under Orders in the portal; anything we could not accept is listed under Rejected orders with the reason.

Products are sized from the weight Shopify sends. To give exact parcels, add an order note attribute cfx_packages holding a JSON list like [{"size":"medium","qty":1,"weight_kg":4}].

WooCommerce

  1. In the portal open Shopify / WooCommerce, save your collection address and copy the WooCommerce address.
  2. In WordPress: WooCommerce › Settings › Advanced › Webhooks › Add webhook. Status Active, topic Order created, paste the address as the delivery URL, and type a secret.
  3. Paste the same secret into the portal as the WooCommerce secret and save.
  4. For the best sizing, install our free CFX Package Data plugin (download it in the portal). It adds each product's weight and size to the order. It does not change prices or checkout.

Your own system

  1. At checkout, call POST /quote and show the total as the delivery price.
  2. When the customer pays, call POST /orders with your order number as external_ref and an Idempotency-Key.
  3. Save the ref and tracking_token. E-mail or show your customer the tracking link if you like (we e-mail it too).
  4. When the parcels are packed, call POST /orders/{ref}/ready.
  5. Listen to webhooks to update the order in your system. If your webhook was down, catch up with GET /orders?before=….

Going live

  • Your business account is approved and your balance is topped up.
  • You create a live key and swap it in. The address stays the same.
  • Keys stay on your server, never in a web page or mobile app.
  • Your webhook checks the signature and answers within 10 seconds.
  • You send an Idempotency-Key or external_ref with every order.

Questions: integrations@charlesfreightx.co.za, or WhatsApp +27 73 020 6951. Please include the X-Request-Id.

WhatsApp