Amigo Developers
Commerce API reference
← All APIs

Commerce API v1

Sell from Amigo's catalog through your own app or storefront. Browse products, place orders charged against your Amigo wallet, and get webhook events for every state change — from order.created to order.delivered.

Overview

The Commerce API exposes the Amigo catalog (currently Nonsman + Oraimo) for resale under your brand. Orders you create are paid out of your Amigo wallet balance, picked + packed by Amigo, and shipped directly to your end customer.

Base URL: https://amigo.ng/api/commerce

Content type: application/json for all POST/PATCH bodies. All responses are JSON.

Money: All prices are integer Naira (no decimals). Responses also include a pre-formatted display string (e.g. "₦4,000").

Rate limiting: Per-token, per-minute. The default is configurable on your API client; exceeding it returns 429 rate_limited.

Authentication

Every request needs an API token. Pass it in any of these headers (whichever your HTTP client makes easiest):

X-API-Key: amg_live_xxxxxxxxxxxxxxxx
# --or--
Authorization: Token amg_live_xxxxxxxxxxxxxxxx
# --or--
Authorization: Bearer amg_live_xxxxxxxxxxxxxxxx

Each token belongs to a single Amigo user + API client. The user_id identifies whose wallet gets debited; the client_id identifies which merchant owns the resulting order.

⚠
Keep tokens out of source control. Generate one per environment (staging vs. production) and rotate if leaked. Whitelisting your IPs is supported on request.

Errors

Errors return a non-2xx status with a consistent envelope:

{
  "success": false,
  "error":   "insufficient_balance",
  "message": "Wallet balance is below the order total."
}

Common error codes:

HTTPerrorWhen
401invalid_tokenMissing/expired/revoked token.
403ip_not_whitelistedYour client has a whitelist and your IP isn't on it.
403admin_requiredEndpoint needs role='admin' on the calling user.
404not_foundThe product, order, or endpoint doesn't exist (or isn't yours).
405method_not_allowedWrong HTTP verb.
409invalid_stateState machine refusal (e.g. ship an unaccepted order).
422invalid_*Body validation failed; message explains.
422insufficient_balanceWallet below the amount due. Only when you send payment.if_unfunded: "fail", or from POST /orders/pay/ — by default a short wallet holds the order as awaiting_payment instead.
422too_many_unpaid_ordersYou already have the maximum number of orders waiting for payment (10 per client and mode). Fund the wallet or cancel some.
409order_expired / not_awaiting_payment/orders/pay/ on an order that is no longer waiting (window passed, already paid, cancelled).
422out_of_stock / insufficient_stockItem ran out between catalog read and order create.
429rate_limitedToo many requests in this minute window.
500server_errorUnexpected. Logged on our end; retry with backoff.

Idempotency

Order creation is the only state-changing endpoint where retries are routinely needed (network drops, mobile flakiness). Send the same Idempotency-Key on retry and you get back the original response — no double-debit, no duplicate order.

curl -X POST https://amigo.ng/api/commerce/orders/ \
  -H "X-API-Key: $TOKEN" \
  -H "Idempotency-Key: ord-2026-05-17-7f3a" \
  -H "Content-Type: application/json" \
  --data '{"customer":{...},"delivery":{...},"items":[...]}'

The key is any opaque string ≤ 80 chars. Scope is per-token; reuse across tokens has no effect. Cache TTL is 24h.

Catalog

GET /api/commerce/products/ Catalog

Paginated product listing with filters.

ParamTypeNotes
categorystringoptionalFilter by category slug (e.g. charging-accessories).
brandstringoptionaloraimo or nonsman.
in_stockbooloptionaltrue to return only in-stock items.
qstringoptionalFree-text search across name + description.
sortstringoptionalprice_asc, price_desc, name, new (default).
limitintoptionalDefault 20, max 100.
offsetintoptionalDefault 0.
curl "https://amigo.ng/api/commerce/products/?category=power-banks&in_stock=true&limit=5" \
  -H "X-API-Key: $TOKEN"
{
  "success": true,
  "data": [
    {
      "id": 42,
      "slug": "oraimo-traveler-3-10000mah-power-bank",
      "brand": "oraimo",
      "name": "Oraimo Traveler 3 10000mAh Power Bank",
      "description": "Slim aluminum body with 22.5W fast charge…",
      "price": {
        "amount":   14500,
        "display":  "₦14,500",
        "currency": "NGN",
        "market":   { "amount": 17000, "display": "₦17,000" }
      },
      "category": { "id": 5, "slug": "power-banks", "name": "Power Banks" },
      "stock":    { "in_stock": true, "count": 27 },
      "rating":   { "value": 4.6, "count": 312 },
      "images":   [ { "position": 1, "url": "https://res.cloudinary.com/…/v1/products/oraimo/traveler-3.jpg" } ],
      "updated_at": "2026-05-16T18:32:11+01:00"
    }
  ],
  "pagination": { "total": 142, "limit": 5, "offset": 0, "has_more": true }
}
GET /api/commerce/products/?id=N or ?slug=X Catalog

Single product. Same shape as a list entry. Use slug for stable URLs in your storefront.

curl "https://amigo.ng/api/commerce/products/?slug=oraimo-traveler-3-10000mah-power-bank" \
  -H "X-API-Key: $TOKEN"
GET /api/commerce/categories/ Catalog

List all categories with product counts. There are currently 14 consolidated categories spanning both brands.

{
  "success": true,
  "data": [
    { "id": 1, "slug": "charging-accessories", "name": "Charging Accessories", "product_count": 183 },
    { "id": 2, "slug": "power-banks",         "name": "Power Banks",           "product_count": 142 }
  ]
}

Delivery

GET /api/commerce/locations.php Public

Master catalog of the 36 Nigerian states + FCT and their 774 Local Government Areas (called cities in the storefront). Public, no auth, cached 5 minutes — safe to call from a browser checkout flow.

ParamTypeNotes
typestringoptionalstates (default) or lgas.
state_idintoptionalWhen type=lgas, filter to one state by id.
state_codestringoptionalWhen type=lgas, filter by ISO-style code — e.g. LA, KD, FCT.
searchstringoptionalTypeahead match across both states and cities. Returns {states:[…], lgas:[…]} (capped 20 / 40).
curl "https://amigo.ng/api/commerce/locations.php?type=states"
{
  "success": true,
  "data": [
    { "id": 25, "code": "LA",  "name": "Lagos",   "capital": "Ikeja",  "region": "South-West",    "sort_order": 250 },
    { "id": 19, "code": "KD",  "name": "Kaduna",  "capital": "Kaduna", "region": "North-West",    "sort_order": 190 }
    // …35 more rows
  ],
  "count": 37
}

List cities in a state:

curl "https://amigo.ng/api/commerce/locations.php?type=lgas&state_code=KD"
{
  "success": true,
  "data": [
    { "id": 142, "state_id": 19, "name": "Kaduna North", "slug": "kaduna-north", "is_capital": 1, "state_code": "KD", "state_name": "Kaduna" },
    { "id": 155, "state_id": 19, "name": "Zaria",        "slug": "zaria",        "is_capital": 0, "state_code": "KD", "state_name": "Kaduna" }
    // …21 more rows
  ],
  "count": 23
}

Typeahead search:

curl "https://amigo.ng/api/commerce/locations.php?search=zar"
{
  "success": true,
  "query":   "zar",
  "states":  [],
  "lgas":    [
    { "id": 155, "name": "Zaria", "state_code": "KD", "state_name": "Kaduna" }
  ]
}
POST /api/commerce/delivery/quote/ Public

Quote shipping for a cart at a specific address. Returns prices for both Standard and Home delivery (premium) tiers plus an ETA range, so the storefront can show the customer their options before checkout. Same resolver as create order — the quote you show is what they'll be charged.

Body shape:

{
  "state_code": "KD",                // or "state_id": 19
  "lga_name":   "Zaria",             // optional · or "lga_id": 155
  "items": [
    { "product_id": 1, "quantity": 2 },
    { "product_id": 5, "quantity": 1 }
  ]
}

Up to 100 line items. quantity isn't used for pricing (delivery charges are per scheme, not per unit) but it's required for shape consistency with /orders/.

curl -X POST https://amigo.ng/api/commerce/delivery/quote/ \
  -H "Content-Type: application/json" \
  --data @quote.json

Success (200):

{
  "success": true,
  "data": {
    "location": {
      "state_id":   19,
      "state_code": "KD",
      "state_name": "Kaduna",
      "lga_id":     155,
      "lga_name":   "Zaria"
    },
    "serviceable": true,
    "schemes": [
      {
        "scheme_id":       1,
        "scheme_name":     "Default Domestic",
        "product_ids":     [1, 5],
        "product_count":   2,
        "all_free":        true,
        "serviceable":     true,
        "tier_resolution": "state",    // 'lga' | 'state' | 'fallback' | 'free'
        "standard": { "price": 1500, "free_for_customer": true,  "eta_min": 0, "eta_max": 2 },
        "premium":  { "price": 5000,                                "eta_min": 0, "eta_max": 2 }
      }
    ],
    "totals":   { "standard": 0, "premium": 5000 },
    "eta":      { "min": 0, "max": 2 },
    "warnings": []
  }
}

Resolution chain — for each unique scheme in the cart:

StepWhat's checkedtier_resolution
1LGA-specific scheme group covering the customer's LGA"lga"
2State-level scheme group covering the customer's state"state"
3The scheme's "rest of Nigeria" fallback row"fallback"
4No match — scheme is serviceable: falsenull

Products without a scheme assigned go into a single scheme_id: null bucket and are always free (tier_resolution: "free").

i
Pricing rules. One charge per unique scheme in the cart (Shopify-style). A scheme's standard tier is free for the customer only when all products in that scheme have free_delivery=true. The premium tier is always paid — free_delivery never zeros it. ETA reported at the cart level is the slowest scheme's range.

Unserviceable (200 with serviceable=false): when a scheme in the cart doesn't ship to the customer's area, the quote still returns 200 so the UI can show which scheme failed. Order create returns 422 unserviceable_delivery in the same situation — see below.

Orders

POST /api/commerce/orders/ Idempotent

Create an order. The Amigo wallet attached to your token is debited inline and the order comes back paid. If the wallet can't cover it, the order is still created — status awaiting_payment, price and stock held for the payment window (24 hours) — and it becomes paid automatically the moment the wallet can cover it. Nothing is dispatched unpaid.

Body shape:

{
  "customer": {
    "name":  "Aisha Bello",           // required, ≤ 120 chars
    "phone": "08012345678",           // required, ≤ 20 chars
    "email": "aisha@example.com"      // optional, must validate
  },
  "delivery": {
    "address":    "Plot 12, Sabon Gari, off PZ Road", // required
    "state_code": "KD",                  // optional · or "state_id": 19
    "lga_name":   "Zaria",               // optional · or "lga_id": 155
    "tier":       "standard",            // optional · "standard" (default) or "premium"
    "city":       "Zaria",               // optional legacy free-text — auto-filled from lga_name when blank
    "state":      "Kaduna",              // optional legacy free-text — auto-filled from the resolved state name
    "notes":      "Call on arrival"
  },
  "items": [
    { "product_id": 42, "quantity": 1 },
    { "product_id": 8,  "quantity": 2 }
  ]
}

Up to 50 distinct line items per order; quantities 1–1000. Prices are snapshotted from the catalog at order time — the merchant can't be surprised by a price change between read and write.

i
Delivery resolution. Pass any of state_id / state_code / lga_id / lga_name in delivery to trigger the scheme-based shipping fee. The server walks the same chain as delivery quote and snapshots the result onto the order. Omit all four for free shipping (legacy back-compat — existing integrations keep working unchanged).
curl -X POST https://amigo.ng/api/commerce/orders/ \
  -H "X-API-Key: $TOKEN" \
  -H "Idempotency-Key: ord-7f3a" \
  -H "Content-Type: application/json" \
  --data @order.json

Success (201):

{
  "success": true,
  "data": {
    "id":             1037,
    "reference":      "AMG-COM-20260520-AB12CD",
    "status":         "paid",
    "payment_state":  "paid",
    "subtotal":       { "amount": 29000, "display": "₦29,000" },
    "delivery_fee":   { "amount":     0, "display": "₦0" },
    "total":          { "amount": 29000, "display": "₦29,000" },
    "customer":       { "name": "Aisha Bello", "phone": "08012345678", "email": "aisha@example.com" },
    "delivery": {
      "address":      "Plot 12, Sabon Gari, off PZ Road",
      "city":         "Zaria",
      "state":        "Kaduna",
      "state_id":     19,
      "lga_id":       155,
      "scheme_id":    1,
      "scheme_name":  "Default Domestic",
      "tier":         "standard",
      "was_free":     true,
      "eta_min_days": 0,
      "eta_max_days": 2,
      "breakdown": [
        { "scheme_id": 1, "scheme_name": "Default Domestic", "tier": "standard", "price": { "amount": 0, "display": "₦0" }, "eta_min_days": 0, "eta_max_days": 2, "product_count": 2 }
      ],
      "notes":        "Call on arrival"
    },
    "items":          [ { "product_id": 42, "name": "Oraimo Traveler 3 …", "quantity": 1, "unit_price": {…}, "line_total": {…} }, … ],
    "created_at":     "2026-05-20 03:12:08",
    "paid_at":        "2026-05-20 03:12:08"
  }
}

On legacy orders (no state_id/lga_id sent), delivery.scheme_id, delivery.tier, delivery.was_free, delivery.eta_* are all null and breakdown is an empty array.

Unserviceable delivery (422): the cart resolves to a scheme that doesn't ship to the given area, and the scheme has no "rest of Nigeria" fallback configured.

{
  "success":  false,
  "error":    "unserviceable_delivery",
  "message":  "One or more products in the cart can't ship to Zaria, Kaduna. Call POST /api/commerce/delivery/quote/ first to see which.",
  "warnings": ["Scheme 'Lagos Metro Only' does not ship to this area."]
}

Invalid delivery location (422): bad state_id / state_code / lga_id. Response carries a field hint pointing at the offending key.

{
  "success": false,
  "error":   "invalid_delivery_location",
  "field":   "state_code",
  "message": "state_code 'XYZ' is not recognised"
}

Wallet short — order held for payment (201): the response is the normal order object with status: "awaiting_payment", plus a payment block that tells you what is due, by when, and how short the wallet is.

{
  "success":          true,
  "payment_required": true,
  "message":          "Order created and held for payment: ₦29,000 is due by 2026-11-15 14:02:11. …",
  "data": {
    "reference":     "AMG-COM-20261114-7F3A1C",
    "status":        "awaiting_payment",
    "payment_state": "unpaid",
    "payment": {
      "state":          "unpaid",
      "is_awaiting":    true,
      "amount_due":     { "amount": 29000, "display": "₦29,000" },   // what YOUR wallet is charged (base + delivery)
      "due_at":         "2026-11-15 14:02:11",
      "wallet_balance": 12500,
      "shortfall":      { "amount": 16500, "display": "₦16,500" },
      "how_to_pay":     "Fund your Amigo wallet … the order completes automatically within a minute. Or POST /api/commerce/orders/pay/ after funding."
    },
    ...
  }
}

While an order waits: its price and stock are locked, order.created has already fired, and every call you make to /orders/ (plus a server job every minute) pays your waiting orders oldest first as soon as the wallet covers them — a newer order never jumps the queue. When one is paid you get order.paid; if the window closes unpaid the order becomes expired, stock is released and you get order.expired. Up to 10 orders per client can wait at once (422 too_many_unpaid_orders beyond that).

Prefer the old behaviour? Send "payment": { "if_unfunded": "fail" } in the body and a short wallet returns 422 insufficient_balance (with required and balance) and creates nothing.

i
Wallet flow. Fund your Amigo wallet through Amigo's standard payment flow (Paystack, bank transfer, the Amigo app). The Commerce API treats wallet balance as the source of truth — there's no card-at-time-of-order path, so no PCI scope ever passes through your app. You don't need to keep a float: let orders in, fund the wallet when they arrive, and they complete on their own.
GET /api/commerce/orders/?ref=AMG-COM-… or ?id=N Scoped

Fetch a single order you created. Scoped to your client_id; another merchant's reference returns 404 not_found.

GET /api/commerce/orders/ Scoped

Paginated list of your own orders, newest first.

ParamTypeNotes
statusstringoptionalawaiting_payment | paid | accepted | shipped | delivered | cancelled | expired
payment_statestringoptionalpaid | refunded | unpaid
fromYYYY-MM-DDoptionalcreated_at ≥ this date 00:00:00
toYYYY-MM-DDoptionalcreated_at ≤ this date 23:59:59
qstringoptionalMatches reference, customer_name, customer_phone.
limitintoptionalDefault 20, max 100.
offsetintoptionalDefault 0.
curl "https://amigo.ng/api/commerce/orders/?status=shipped&limit=10" \
  -H "X-API-Key: $TOKEN"
{
  "success":    true,
  "data":       [ { ...order... }, ... ],
  "pagination": { "total": 87, "limit": 10, "offset": 0, "has_more": true, "next_offset": 10 }
}
POST /api/commerce/orders/pay/ Scoped

Pay one of your awaiting_payment orders from your wallet right now. You rarely need to call it — waiting orders are paid automatically within a minute of the wallet being funded, and on your next call to /orders/ — but it is the "I just topped up, settle it now" button, and it tells you exactly how short you are if the wallet still can't cover it.

{ "reference": "AMG-COM-20261114-7F3A1C" }      // or { "id": 123 }
StatusMeaning
200Paid. data is the order (now status: "paid", payment.charged set). order.paid fires.
422 insufficient_balanceStill short: required, balance, shortfall, and data (the order) are returned. Nothing changes.
409 order_expiredThe window closed while you were funding; the order was released (expired). Create a new one.
409 not_awaiting_paymentAlready paid, cancelled or expired — data shows the current order.
curl -X POST https://amigo.ng/api/commerce/orders/pay/ \
  -H "X-API-Key: $TOKEN" \
  -H "Content-Type: application/json" \
  --data '{"reference":"AMG-COM-20261114-7F3A1C"}'
POST /api/commerce/orders/transition/ Admin only

Move an order forward in fulfillment, or cancel + refund it. Calling user must have role='admin'.

Body:

{
  "reference": "AMG-COM-20260517-AB12CD",    // required
  "action":    "accept" | "ship" | "deliver" | "cancel",
  "reason":    "out of stock at warehouse"      // optional, used by cancel
}

State machine:

From statusActionTo statusSide effects
paid accept accepted —
accepted ship shipped shipped_at = now()
shipped deliver delivered delivered_at = now()
paid/acceptedcancel cancelled Stock restored, wallet refunded what it was actually charged (payment.charged), payment_state='refunded'
awaiting_paymentcancel cancelled Stock restored; nothing to refund — the wallet was never charged. accept on an awaiting order returns 409 awaiting_payment: nothing ships unpaid.
curl -X POST https://amigo.ng/api/commerce/orders/transition/ \
  -H "X-API-Key: $ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  --data '{"reference":"AMG-COM-20260517-AB12CD","action":"ship"}'

Each successful transition fires a webhook event (order.accepted, order.shipped, order.delivered, order.cancelled) to every endpoint whose events filter matches.

⚠
Cancel is a one-way door. A cancelled order can't be un-cancelled. Stock restore + wallet refund happen atomically — if either fails you'll see a 500 and the operation is rolled back.

Webhooks

Subscribe to order lifecycle events so you don't have to poll. Webhooks are HTTPS POSTs with a JSON body and an HMAC-SHA256 signature. Failed deliveries retry on an exponential schedule (1m, 5m, 30m, 2h, 12h, 24h — 7 attempts max).

POST /api/commerce/webhooks/

Register a new endpoint. The plaintext signing secret is returned once in the 201 response — store it then; later GETs will not include it.

{
  "url":    "https://your-app.com/amigo/webhook",    // required, http(s), ≤ 512 chars
  "events": "*"                                  // "*" all, "order.*" prefix, or "order.shipped,order.delivered"
}
{
  "success": true,
  "data": {
    "id":     12,
    "url":    "https://your-app.com/amigo/webhook",
    "events": "*",
    "status": "active",
    "secret": "a3f1…64-char hex…"     // ← save this NOW
  },
  "message": "Save this secret now — it will not be shown again."
}
GET /api/commerce/webhooks/

List your registered endpoints (no secrets).

GET /api/commerce/webhooks/?id=N

Single endpoint plus its 20 most recent delivery attempts (status, attempts, response code, scheduled retry time).

PATCH /api/commerce/webhooks/?id=N

Update url, events, or status (active/disabled). Disabled endpoints stop receiving new events but keep their delivery history.

DELETE /api/commerce/webhooks/?id=N

Permanently remove the endpoint and its delivery history (FK cascade).

Event reference

EventWhenPayload data
order.created POST /orders succeeded — status is paid (wallet debited) or awaiting_payment (held; see data.payment). Full order object
order.paid A held order was paid from the wallet (automatically, or via /orders/pay/). Full order object (payment.charged set)
order.expired A held order was not paid within its window; stock released. Full order object (payment.expired_at)
order.accepted Admin transitioned paid → accepted. Full order object
order.shipped Admin transitioned accepted → shipped. Full order object
order.delivered Admin transitioned shipped → delivered. Full order object
order.cancelled Order was cancelled + refunded. Full order object (incl. cancelled_reason)

Wire format:

POST https://your-app.com/amigo/webhook  HTTP/1.1
Host: your-app.com
Content-Type: application/json
User-Agent: Amigo-Commerce-Webhook/1.0
X-Amigo-Event:     order.shipped
X-Amigo-Delivery:  4831
X-Amigo-Signature: sha256=8c4f…

{
  "event":      "order.shipped",
  "created_at": "2026-05-17T03:48:11+01:00",
  "data":       { ...full order... }
}

Verifying signatures

Every request includes X-Amigo-Signature: sha256=<hex>, computed as hmac_sha256(secret, raw_body_bytes). Always verify before trusting the payload — anyone could POST to your endpoint URL, but only requests signed with your endpoint's secret are real.

<?php
$body   = file_get_contents('php://input');
$sig    = $_SERVER['HTTP_X_AMIGO_SIGNATURE'] ?? '';
$secret = 'a3f1…64-char hex…';       // the one returned at register-time

$expected = 'sha256=' . hash_hmac('sha256', $body, $secret);
if (!hash_equals($expected, $sig)) {
    http_response_code(401);
    exit('bad signature');
}

$event = json_decode($body, true);
// $event['event']      → "order.shipped"
// $event['data']       → full order object
// $event['created_at'] → ISO 8601
const crypto = require('crypto');

app.post('/amigo/webhook', express.raw({ type: 'application/json' }), (req, res) => {
    const body   = req.body;             // Buffer — verify against bytes!
    const sig    = req.get('X-Amigo-Signature') || '';
    const secret = process.env.AMIGO_WEBHOOK_SECRET;

    const expected = 'sha256=' + crypto.createHmac('sha256', secret).update(body).digest('hex');
    if (!crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(sig))) {
        return res.status(401).send('bad signature');
    }

    const event = JSON.parse(body.toString());
    // handle event.event …
    res.status(200).send('ok');
});
import hmac, hashlib

@app.route('/amigo/webhook', methods=['POST'])
def webhook():
    body   = request.get_data()           # raw bytes, NOT request.json
    sig    = request.headers.get('X-Amigo-Signature', '')
    secret = os.environ['AMIGO_WEBHOOK_SECRET'].encode()

    expected = 'sha256=' + hmac.new(secret, body, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(expected, sig):
        return 'bad signature', 401

    event = json.loads(body)
    # handle event['event'] …
    return 'ok', 200
!
Sign the bytes, not the parsed JSON. Any framework that re-serializes the body will scramble whitespace and break the signature. Read raw bytes first, verify, then parse.

Retry behaviour

If your endpoint doesn't return a 2xx within 4 seconds, the delivery is queued for retry. The schedule (in seconds since the previous attempt):

  • Attempt 1 → +60s
  • Attempt 2 → +300s (5m)
  • Attempt 3 → +1800s (30m)
  • Attempt 4 → +7200s (2h)
  • Attempt 5 → +43200s (12h)
  • Attempt 6 → +86400s (24h)
  • Attempt 7 → marked exhausted, no further attempts

The X-Amigo-Delivery header is the immutable id of that delivery — use it to dedupe. Two requests with the same delivery id are the same event being retried; idempotent processing on your side is essential.