ZR Express Delivery Integration
ZR Express is an Algerian cash-on-delivery delivery platform
(https://api.zrexpress.app, dashboard zrexpress.app). Its REST API covers the
full supplier flow: parcels/orders (create, bulk, exchange, refund, labels,
state updates), catalog (products, stock, receipts), customers
(individual + company, addresses, imports), claims, delivery pricing
(rates per territory), treasury (payments, payment requests, balance),
users (profile, API keys), hubs, and webhooks (programmatic
registration).
Start at references/ in this folder — do not guess from the raw swagger.
Read CONFORMANCE.md before assuming the current adapter behavior is correct —
it lists live-verified bugs (tracking 404, delete 405, address update 400, stop-desk
hub 404, geo naming) that the code comments below may not reflect.
Reference files (in this skill folder)
| File |
What it holds |
endpoints-index.md |
Master index — all 129 endpoints, per-domain, with auth notes |
CONFORMANCE.md |
Verified audit (2026-09-10, live-tested): what works / what's broken / fix order — read before assuming current behavior is correct |
references/catalog.md |
Products, stock movements, receipts, categories, catalog reports (17) |
references/claims.md |
Claim categories, claims, comments, workflows (11) |
references/customers.md |
Individual/company customers, addresses, imports/exports (15) |
references/orders.md |
Parcels, pickup bags, modification requests, territories, labels, reports (50) |
references/delivery-pricing.md |
Rates, service pricing, price lists (5) |
references/hubs.md |
Hubs (2) |
references/supplier.md |
Supplier profile, blocking, price-list assignments (3) |
references/treasury.md |
Supplier payments, payment requests, treasury reports (15) |
references/users.md |
Profile, API-key management (4) |
references/webhooks.md |
Webhook endpoint CRUD (7) |
schemas/*.json |
Full request/response schemas per domain (verbatim from swagger) |
Path prefix is /api/v1/… (version defaults to 1). Read the domain
reference + its schemas/{domain}.json before writing adapter code.
Codebase
cod-server/src/endpoints/delivery-companies/providers/zr_express/ — the adapter
(adapter.ts, types.ts, capabilities.ts) implementing the
DeliveryProvider interface used by dispatch.ts.
cod-server/src/endpoints/delivery-companies/providers/registry.ts — routes
company code zr_express to the adapter; apiToken = ZR API key,
apiUserGuid = ZR tenant Id.
cod-server/src/endpoints/delivery-companies/webhook-handlers.ts — programmatic
webhook registration (registerZrWebhook) against /api/v1/webhooks/endpoints.
cod-server/src/endpoints/webhooks/zr-status-mapper.ts — maps ZR state names
to CodFlow statuses.
Auth
- Headers:
X-Api-Key: {secretKey} + X-Tenant: {tenantId}
(the adapter uses these consistently; the swagger also lists Bearer).
- Every request also carries
Accept/Content-Type application/json.
Gotchas (verified against the live integration)
- No separate validation step — ZR auto-activates parcels on creation;
validateShipment is a no-op.
- Single create returns a parcel UUID; the tracking number only comes back from
GET /parcels/{id}. Bulk create (POST /parcels/bulk) returns the
tracking number directly. maxBulkCreate = 100.
- Territories are UUIDs (city + district), not
wilaya_id/commune strings —
resolve them via POST /territories/search and cache the city per wilaya.
- Auth is
X-Api-Key + X-Tenant — do not switch to Authorization: Bearer
just because examples show it; the stored apiToken is an API key.
- State names are free text (
data.state.name), not a fixed enum: only
"Out for Delivery", "In Transit" and "At Hub" are documented defaults.
Unknown names must surface as unmapped — never guessed into a status.
- Label URLs expire (~1 hour, SAS-token based) — from create you get a
deferred label token (CodFlow uses
DEFERRED_LABEL_MARKER); serve labels
server-side, never expose a signed URL to the browser.
- Update semantics —
PATCH /parcels/{id}/amount, /customer and
/deliveryAddress apply while canUpdateAfterValidation: true.
- Delete is unreliable (HTTP 405 in tests) —
canDeleteBeforeValidation/
AfterValidation are both false; prefer state updates/refund flows.
- Webhook registration is API-driven —
POST /webhooks/endpoints with
X-Api-Key + X-Tenant; the registered URL is CodFlow's /webhooks/zr_express.
- All IDs (parcel, customer, address, claim, etc.) are UUIDs — any other
format is an error or a legacy/alias field.
Workflow A — Connect ZR Express
- Create the delivery company with
code: "zr_express", apiToken = ZR API key,
apiUserGuid = ZR tenant Id.
- Verify: token check → create a test parcel (
POST /parcels,
POST /customers/individual first) → GET /parcels/{id} returns the tracking
number → POST /parcels/labels/individual → tracking pull
(GET /parcels/{id}/state-history).
- Register the webhook (
registerZrWebhook → POST /webhooks/endpoints) and
configure webhook_status_mapping for any non-default state names.
Workflow B — Audit / fix the integration
- Read the relevant
references/{domain}.md + schemas/{domain}.json.
- Diff
adapter.ts / types.ts endpoint-by-endpoint against the reference.
- Keep every header name, path, query param, and body field exactly as the
reference spells them (the generated files are verbatim from swagger).
Security
Never commit ZR API keys or tenant IDs. They live in wrangler secrets /
.dev.vars only (repo convention).
1---2name: zr-express3description: ZR Express delivery platform integration for CodFlow — all 129 public API endpoints (catalog, claims, customers, orders/parcels, delivery pricing, hubs, supplier, treasury, users, webhooks), organized per domain. Use when connecting ZR Express as a delivery company, auditing or fixing the zr_express adapter in cod-server, verifying behavior against the official API, pulling tracking/state, registering webhooks, or extending ZR Express support.4metadata:5 source: https://skillmd.com/skills/bighadj22/zr-express6---78# ZR Express Delivery Integration910ZR Express is an Algerian cash-on-delivery delivery platform11(`https://api.zrexpress.app`, dashboard `zrexpress.app`). Its REST API covers the12full supplier flow: **parcels/orders** (create, bulk, exchange, refund, labels,13state updates), **catalog** (products, stock, receipts), **customers**14(individual + company, addresses, imports), **claims**, **delivery pricing**15(rates per territory), **treasury** (payments, payment requests, balance),16**users** (profile, API keys), **hubs**, and **webhooks** (programmatic17registration).1819Start at `references/` in this folder — do not guess from the raw swagger.20**Read `CONFORMANCE.md` before assuming the current adapter behavior is correct** —21it lists live-verified bugs (tracking 404, delete 405, address update 400, stop-desk22hub 404, geo naming) that the code comments below may not reflect.2324## Reference files (in this skill folder)2526| File | What it holds |27|---|---|28| `endpoints-index.md` | Master index — all 129 endpoints, per-domain, with auth notes |29| `CONFORMANCE.md` | **Verified audit (2026-09-10, live-tested): what works / what's broken / fix order** — read before assuming current behavior is correct |30| `references/catalog.md` | Products, stock movements, receipts, categories, catalog reports (17) |31| `references/claims.md` | Claim categories, claims, comments, workflows (11) |32| `references/customers.md` | Individual/company customers, addresses, imports/exports (15) |33| `references/orders.md` | **Parcels, pickup bags, modification requests, territories, labels, reports (50)** |34| `references/delivery-pricing.md` | Rates, service pricing, price lists (5) |35| `references/hubs.md` | Hubs (2) |36| `references/supplier.md` | Supplier profile, blocking, price-list assignments (3) |37| `references/treasury.md` | Supplier payments, payment requests, treasury reports (15) |38| `references/users.md` | Profile, API-key management (4) |39| `references/webhooks.md` | Webhook endpoint CRUD (7) |40| `schemas/*.json` | Full request/response schemas per domain (verbatim from swagger) |4142Path prefix is `/api/v1/…` (`version` defaults to `1`). Read the domain43reference + its `schemas/{domain}.json` before writing adapter code.4445## Codebase4647- `cod-server/src/endpoints/delivery-companies/providers/zr_express/` — the adapter48 (`adapter.ts`, `types.ts`, `capabilities.ts`) implementing the49 `DeliveryProvider` interface used by `dispatch.ts`.50- `cod-server/src/endpoints/delivery-companies/providers/registry.ts` — routes51 company code `zr_express` to the adapter; `apiToken` = ZR API key,52 `apiUserGuid` = ZR **tenant Id**.53- `cod-server/src/endpoints/delivery-companies/webhook-handlers.ts` — programmatic54 webhook registration (`registerZrWebhook`) against `/api/v1/webhooks/endpoints`.55- `cod-server/src/endpoints/webhooks/zr-status-mapper.ts` — maps ZR state names56 to CodFlow statuses.5758## Auth5960- Headers: `X-Api-Key: {secretKey}` **+** `X-Tenant: {tenantId}`61 (the adapter uses these consistently; the swagger also lists `Bearer`).62- Every request also carries `Accept`/`Content-Type` `application/json`.6364## Gotchas (verified against the live integration)65661. **No separate validation step** — ZR auto-activates parcels on creation;67 `validateShipment` is a no-op.682. **Single create returns a parcel UUID**; the tracking number only comes back from69 `GET /parcels/{id}`. **Bulk create** (`POST /parcels/bulk`) returns the70 tracking number directly. `maxBulkCreate` = 100.713. **Territories are UUIDs** (city + district), not `wilaya_id`/commune strings —72 resolve them via `POST /territories/search` and cache the city per wilaya.734. **Auth is `X-Api-Key` + `X-Tenant`** — do not switch to `Authorization: Bearer`74 just because examples show it; the stored `apiToken` is an API key.755. **State names are free text** (`data.state.name`), not a fixed enum: only76 `"Out for Delivery"`, `"In Transit"` and `"At Hub"` are documented defaults.77 Unknown names must surface as `unmapped` — never guessed into a status.786. **Label URLs expire (~1 hour, SAS-token based)** — from create you get a79 deferred label token (CodFlow uses `DEFERRED_LABEL_MARKER`); serve labels80 server-side, never expose a signed URL to the browser.817. **Update semantics** — `PATCH /parcels/{id}/amount`, `/customer` and82 `/deliveryAddress` apply while `canUpdateAfterValidation: true`.838. **Delete is unreliable** (HTTP 405 in tests) — `canDeleteBeforeValidation`/84 `AfterValidation` are both false; prefer state updates/refund flows.859. **Webhook registration is API-driven** — `POST /webhooks/endpoints` with86 `X-Api-Key` + `X-Tenant`; the registered URL is CodFlow's `/webhooks/zr_express`.8710. All IDs (parcel, customer, address, claim, etc.) are **UUIDs** — any other88 format is an error or a legacy/alias field.8990## Workflow A — Connect ZR Express91921. Create the delivery company with `code: "zr_express"`, `apiToken` = ZR API key,93 `apiUserGuid` = ZR **tenant Id**.942. Verify: token check → create a test parcel (`POST /parcels`,95 `POST /customers/individual` first) → `GET /parcels/{id}` returns the tracking96 number → `POST /parcels/labels/individual` → tracking pull97 (`GET /parcels/{id}/state-history`).983. Register the webhook (`registerZrWebhook` → `POST /webhooks/endpoints`) and99 configure `webhook_status_mapping` for any non-default state names.100101## Workflow B — Audit / fix the integration1021031. Read the relevant `references/{domain}.md` + `schemas/{domain}.json`.1042. Diff `adapter.ts` / `types.ts` endpoint-by-endpoint against the reference.1053. Keep every header name, path, query param, and body field **exactly** as the106 reference spells them (the generated files are verbatim from swagger).107108## Security109110Never commit ZR API keys or tenant IDs. They live in `wrangler secrets` /111`.dev.vars` only (repo convention).