# Codera PharmX: Storefront API Read-only HTTP/JSON API over one pharmacy's WHOLESALE catalogue: products, prices, availability, categories and shop details. Built for storefronts and price lists. Base URL: https://www.pharmx.online/api/public/v1 Auth: Authorization: Bearer (or X-Api-Key: ) Keys: psk_live_… / psk_test_…, issued per pharmacy, revocable, scoped. ## Rules that are expensive to get wrong 1. PRICES ALREADY INCLUDE VAT. Every "price" is GROSS. Never add VAT on top. To show the tax component, EXTRACT it: vat = price - price / (1 + rate). The rate is "vatRatePercent" from /business. Every response repeats "priceIncludesVat": true in meta so this cannot be missed. 2. "availability" IS A BAND, NOT A COUNT. Values: "in_stock", "low_stock", "out_of_stock". The threshold behind "low_stock" is the pharmacy's private reorder level and is never published. Exact numbers require the "stock:exact" scope and are opt-in per key. 3. STOCK IS NOT LIVE. Levels reach this API only when a till syncs: within seconds when the shop is online, not at all while it is offline. Every response carries "stockAsOf" (ISO 8601). Show it. Say "as of 10 minutes ago", never "in stock now". /health returns "stockAgeSeconds" for the same reason: a large age means the shop is closed or offline, NOT that the API is down. 4. THERE IS NO ORDERING ENDPOINT, deliberately. Because of (3) you cannot reserve against these numbers. Collect a basket and send it to the pharmacy as a REQUEST they confirm out of band. 5. POLL THE DELTA, NOT THE CATALOGUE. Use /stock?updatedSince=. Items whose level did not change are left out of the response entirely. 6. SEND If-None-Match. /products and /stock return an ETag. Send it back and an unchanged poll answers 304 with no body, without the server reading the catalogue at all. Most polls find nothing changed, so this is most of them. ## Endpoints GET /products scope: catalog:read cache: 30s The published wholesale catalogue, paginated. page (integer): 1-based. Default 1. limit (integer): Default 50, maximum 200. search (string): Matches name, code or description, case-insensitive. category (string): A category key from /categories. updatedSince (ISO 8601): Only products changed at or after this time. GET /products/{code} scope: catalog:read cache: 30s One product by its code. code (string): The product code, in the path. GET /stock scope: stock:read cache: 20s Availability only: code and band. The cheap poll. updatedSince (ISO 8601): Returns only items whose level changed since. Items with no change are omitted entirely. GET /categories scope: catalog:read cache: 5m Category keys and labels. Only categories with published products. GET /business scope: catalog:read cache: 10m Shop name, contact details, logo and the VAT rate. GET /health scope: catalog:read cache: none Liveness, and how stale the stock picture is. ## Response envelope List and single-object endpoints (all except /health): { "data": , "meta": { "currency": "MWK", "priceIncludesVat": true, "stockAsOf": "2026-08-22T09:14:03.221Z", "page": 1, "limit": 50, "total": 218, "totalPages": 5 } } Pagination keys appear on /products only. "count" appears on /stock and /categories. ## Product object { "code": "WS-00042", "name": "Paracetamol 500mg", "description": "Box of 24 blisters", "category": "analgesics", "unit": "Box", "unitsPerPack": 24, "price": 12500, "taxable": true, "availability": "in_stock", "updatedAt": "2026-08-21T16:02:11.000Z" } "unitsPerPack" is how many retail base-units are in one wholesale unit, so a buyer can compare a box price against a per-unit one. "quantityAvailable" (integer) is added only with the "stock:exact" scope. ## Business object { "name", "address", "phone", "email", "website", "logo": "", "vatRatePercent": 17.5 } ## Health object (no envelope) { "status": "ok", "pharmacy", "stockAsOf", "stockAgeSeconds", "timestamp" } ## Errors Uniform shape. Branch on "code", never on the message: { "error": { "code": "invalid_key", "message": "Invalid API key" } } 401 missing_key No Authorization or X-Api-Key header. 401 invalid_key Unknown, revoked or expired. Deliberately not distinguished. 403 insufficient_scope The key lacks the scope this endpoint needs. 403 storefront_disabled The pharmacy has not switched its storefront on. 403 tenant_inactive The pharmacy's account is suspended. 403 origin_not_allowed Browser request from an origin that is not allowlisted. 400 invalid_parameter A parameter was malformed, usually a bad date. 404 not_found No such product, or it is not published. 429 rate_limited Too many requests in the last minute. 500 internal_error Our fault. Safe to retry with backoff. ## Conditional requests /products and /stock return an ETag. Keep it per URL and send it back: GET /stock?updatedSince=2026-08-22T09:14:03.221Z If-None-Match: W/"zEDEoaUj6RvIAf-YZ5Vxyx" -> 304 Not Modified, empty body, same ETag 304 means nothing has changed since that tag; keep what you have and do not advance your cursor. The tag covers stock movements AND catalogue edits (including a product being published or hidden), so a 304 is a real "nothing to do". It also covers the query, so each distinct URL has its own tag. ## Cursor handling Advance your cursor only after a successful 200, and overlap it slightly: cursor = new Date(Date.parse(meta.stockAsOf) - 5000).toISOString(); The five seconds cost you a few rows you already have (applying a band twice is harmless) and protect against a write that lands while your request is already in flight. Advancing to exactly meta.stockAsOf can skip it, and a skipped change is never retried. ## Rate limits 120 requests per minute per key by default. Exceeding it returns 429. Retry with exponential backoff. The limiter is per server instance, so treat it as protection against a runaway client rather than as a precise quota. ## CORS Server-to-server calls send no Origin header and are not subject to CORS. Browser calls are allowed only from origins the pharmacy has allowlisted; there is no wildcard, because these responses are credential-gated. Do NOT put an API key in browser JavaScript. It is a bearer credential and anyone who views source can take it. Call this API from your backend and serve your own frontend from there. ## Recommended ingestion 1. Once: page /products?page=N&limit=200 until page >= meta.totalPages. Store meta.stockAsOf as your cursor. 2. Every 60s: GET /stock?updatedSince= with If-None-Match. On 304 do nothing. On 200 apply the returned bands and advance the cursor to meta.stockAsOf minus a 5s overlap. 3. Every 15m: GET /products?updatedSince= to pick up new products and price or name changes. 4. Daily: GET /categories and /business. 5. Display meta.stockAsOf next to availability.