Connect a website to Haatly
Your shop's website can run anywhere — your own server, WordPress, Shopify. It talks to Haatly over HTTPS: it sends orders in and reads products, prices and stock. Haatly calls the site back with webhooks when something changes, so stock stays right everywhere.
- In the dashboard, open the business → Connections → Connect a website.
- Copy the API key (shown once) into the website's server settings.
- Optionally give a webhook address and copy the signing secret.
Two ways to connect. A store built on Haatly core stays the master copy of its products, stock and orders — shop staff keep working in its admin — and reports to Haatly with the store connector endpoints, so the owner can follow every shop from one place. Other sites can instead let Haatly be the master: they read products and stock from Haatly and send orders in (the Haatly-managed endpoints).
Base address: https://haatly.shop/api/v1 · JSON in, JSON out · money is a string with 2 decimals ("1250.00") in the business's currency · times are ISO 8601 UTC.
Authentication
Every request carries the connection's key. Keys belong to one business; they can only see and change that business. Keep the key on the server — never in browser JavaScript or a mobile app.
curl https://haatly.shop/api/v1/ping \ -H "Authorization: Bearer hk_live_…"
{ "ok": true,
"business": { "name": "Fashion House", "slug": "fashion-house", "currency": "BDT", "country": "BD", "timezone": "Asia/Dhaka" },
"connection": { "id": 3, "name": "Main website", "platform": "custom", "events": ["order.created", "…"] } }
A paused connection gets 403 connection_paused; a replaced key gets 401 invalid_key.
Errors & limits
Errors always look like this. fields appears on validation errors, keyed by the JSON path.
HTTP/1.1 422
{ "error": { "code": "validation_failed", "message": "Some fields are missing or invalid.",
"fields": { "customer.phone": "Enter a Bangladeshi mobile number, e.g. 01712345678." } } }
| Status | Code | Meaning |
|---|---|---|
| 401 | unauthenticated, invalid_key | No key, or not a current key |
| 403 | connection_paused | Paused in the dashboard |
| 404 | not_found | No such product / order for this connection |
| 409 | out_of_stock, cannot_cancel | Not enough stock; order already shipped |
| 422 | validation_failed, unknown_items | Bad input; a SKU that isn't in Haatly |
| 429 | rate_limited | More than 120 requests a minute for this connection — retry after the RateLimit reset |
Store connector (Haatly core)
For stores built on Haatly core (storicart, deshghor, …). The store is the master; Haatly keeps a read-only mirror for the owner's overview, per-shop stats and alerts. Haatly never changes a mirrored product's stock or an order's status, and never sends mirrored records back out as webhooks.
All endpoints use the connection's API key. Every record carries the store's own id as external_id (unique per store, any string up to 100 characters) and, ideally, updated_at: Haatly ignores an update older than what it already holds ("status": "stale"), so retries and out-of-order sends are safe.
Heartbeat — POST /sync/heartbeat
Every 5–15 minutes. Haatly marks the store "Not reporting" after 2 hours without one. The reply includes what Haatly holds, so the connector can tell if a full sync is needed.
POST /sync/heartbeat
{ "app": "storicart", "app_version": "1.4.0", "core_version": "2.3.1",
"site_url": "https://storicart.com", "admin_url": "https://storicart.com/admin",
"counts": { "products": 120, "orders": 904 } }
200 { "ok": true, "state": { "products": { "count": 118, "last_updated_at": "…" }, "orders": { "count": 904, "last_updated_at": "…" }, … } }
GET /sync/state returns the same state on its own.
Products — PUT /sync/products/:external_id
Send the whole product each time it changes (create or update). Variants the store no longer sends are retired. A simple product sends one variant.
PUT /sync/products/1842
{
"name": "Cotton Panjabi", "status": "active", // active · draft · archived
"category": "Men", "description": "<p>…</p>",
"image_url": "https://storicart.com/uploads/panjabi.jpg",
"options": [{ "name": "Size", "values": ["M", "L"] }],
"track_inventory": true,
"variants": [
{ "external_id": "1842-M", "sku": "PJ-M", "title": "M", "options": ["M"], "price": 2450, "compare_at_price": 2900, "cost": 1150, "stock": 7 },
{ "external_id": "1842-L", "sku": "PJ-L", "title": "L", "options": ["L"], "price": 2450, "stock": 2 }
],
"updated_at": "2026-11-10T08:00:00Z"
}
201 { "data": { "external_id": "1842", "status": "created", "id": 311 } } // later: 200 "updated" or "stale"
DELETE /sync/products/:external_id archives it in Haatly. SKUs must be unique within the store (not across stores).
Stock only — PUT /sync/inventory
{ "items": [{ "external_id": "1842-M", "stock": 5 }, { "sku": "PJ-L", "stock": 0 }] } // up to 1000
200 { "data": [{ "external_id": "1842-M", "sku": "PJ-M", "status": "updated", "stock": 5 }, …] }
Orders — PUT /sync/orders/:external_id
Send the whole order when it is placed and every time it changes (status, payment, courier). Map the store's statuses to Haatly's: pending, confirmed, processing (packing), shipped, delivered, cancelled, returned; send the store's own wording too as store_status.
PUT /sync/orders/90215
{
"number": "SC-5001", "status": "shipped", "store_status": "With courier",
"customer": { "name": "Nusrat Jahan", "phone": "01712345678", "email": null,
"address": "House 12, Road 4, Mirpur 10", "area": "Mirpur", "district": "Dhaka" },
"items": [{ "variant_external_id": "1842-M", "sku": "PJ-M", "name": "Cotton Panjabi", "variant": "M", "quantity": 2, "unit_price": 2450, "unit_cost": 1150 }],
"discount": 0, "delivery_charge": 60, // subtotal / total optional — Haatly computes them
"payment": { "method": "bkash", "status": "paid" }, // unpaid · partial (+ paid_amount) · paid · refunded
"courier": { "provider": "Steadfast", "consignment_id": "987654", "tracking_code": "SFR1234ABCD", "status": "in_review" },
"note": "Call before delivery",
"placed_at": "2026-11-10T07:30:00Z", "updated_at": "2026-11-10T10:00:00Z"
}
Cost prices are optional and only used for profit reports: send a variant's cost if the store keeps one (leave it out otherwise — owners can type costs into Haatly, and a sent cost replaces the typed one). unit_cost on an order line is the cost when it was sold.
Haatly links the customer by phone across all shops of the business, so the owner sees one customer record and the fake-order check uses every shop's history.
Full sync — batches
POST /sync/products with { "products": [ … ] } and POST /sync/orders with { "orders": [ … ] }, up to 100 per request (5 MB). Each record is checked on its own; the reply lists a result per record and a summary such as { "created": 98, "updated": 1, "invalid": 1 } — invalid ones carry fields explaining why. Run a full sync on first connect and nightly; send single records as things change.
Requests from the owner — GET /sync/commands
From Haatly an owner can ask the store to confirm or cancel an order, or pause or resume a product. Haatly never changes the store's data itself. The request reaches the store by webhook (X-Haatly-Event: store.command, signed) if the connection has a webhook address, and is always available by polling; the heartbeat reply's pending_commands says when to poll.
GET /sync/commands
{ "data": [{ "id": 42, "type": "order.cancel", "external_id": "90215", "reason": "Customer asked on WhatsApp",
"requested_by": "Raihan Ahmed", "requested_at": "…", "expires_at": "…" }] }
POST /sync/commands/42/ack
{ "status": "done" } // or { "status": "failed", "message": "Already handed to courier" }
Types: order.confirm, order.cancel (with reason), product.pause, product.resume. After acting, re-send the order or product so Haatly shows the new state. Requests expire after 24 hours; acknowledging a withdrawn or finished request returns 409. Handle each id once — it can arrive by webhook and by polling.
What the connector does, in short
- Settings in the store admin: Haatly URL, API key, on/off.
- On product save/delete, stock change, and order create/update: queue a send (retry with back-off on network errors or 5xx; give up and log on 4xx).
- Every 5–15 min: heartbeat; if
pending_commands> 0, fetch and carry out the owner's requests, then ack them. - Nightly (and from a "Sync now" button): full sync in batches of 100.
- Respect
429(rate limit, 120 requests/min) by waiting for theRateLimitreset.
WooCommerce plugin
A WooCommerce shop doesn't need any code: install the Haatly Connector plugin and it does everything in the store connector section above. Download the plugin (WordPress 6.2+, WooCommerce 7.1+, PHP 7.4+; works with HPOS order tables).
- In Haatly: business → Connections → Connect a website → runs on WooCommerce. Copy the API key.
- In WordPress: Plugins → Add New → Upload Plugin → Activate. Then WooCommerce → Haatly: paste the key, tick On, Save and connect. The shop sends everything it has in the background.
- Optional, for instant requests: set the connection's webhook to
https://your-shop/wp-json/haatly/v1/webhookand paste its signing secret into the plugin.
How WooCommerce maps to Haatly
| WooCommerce | Haatly |
|---|---|
| Simple product | One variant; its external_id is the product id |
| Variable product | Variations become variants (up to 3 variation attributes become options; "any" shows as Any) |
| Sale price / regular price | Price / compare-at price |
| Published / draft, pending, private / bin | active / draft / archived |
| Pending payment, On hold | pending |
| Processing | confirmed |
| Completed | delivered |
| Cancelled, Failed / Refunded | cancelled / returned |
| Statuses from other plugins ("Shipped", "Confirmed", "Packing", "Returned"…) | Matched by name; the shop can change any of these under Order statuses |
| Order total (fees, tax), coupons, shipping | total, discount, delivery charge |
| Paid date / fully refunded | paid / refunded |
| Gateways cod, bkash*, nagad*, sslcommerz*, bacs | cod, bkash, nagad, sslcommerz, bank (others shown as Other) |
| State (e.g. BD-13) | district (Dhaka) |
Orders without a phone number are not sent (Haatly links customers by phone); the plugin's activity log lists them. Owner requests: confirm moves a pending order to Processing (or the shop's own "Confirmed" status); cancel uses WooCommerce's cancel, which puts stock back, and is refused once an order has shipped; pause sets the product to draft and resume publishes it again.
Developers can adjust what is sent with the filters haatly_connector_product, haatly_connector_order (return null to skip) and haatly_connector_order_courier (return provider, consignment_id, tracking_code, status from a courier plugin).
Shopify
Shopify shops don't run Haatly's code: Haatly reads the shop through Shopify's Admin API and keeps the same read-only mirror as other stores. Nothing to install in the theme.
- In Shopify: Settings → Apps → Develop apps → Build apps in Dev Dashboard. Create an app in the shop's own organization.
- Access scopes:
read_products,read_inventory,read_orders; addwrite_orders,write_productsto act from Haatly andread_all_ordersfor older orders. Allow protected customer data (name, phone, address). Release and install. - In Haatly: Connect a website → Shopify → paste the shop address, Client ID and Client secret → Save and test.
Since January 2026 Shopify issues 24-hour tokens for such apps (client credentials); Haatly renews them itself. Shops with an older custom app can paste its shpat_… token instead. Updates arrive by Shopify webhooks (signature-checked) with a 10-minute catch-up. Tags Confirmed, Packed, Delivered and Returned set the order's status in Haatly; confirming from Haatly adds the Confirmed tag. Variant unit costs are used for profit.
Haatly-managed: products
GET /products — active products, 50 per page (max 100). Query: page, per_page, status (active · draft · archived · all), updated_since (only products whose details, prices or stock changed since then).
GET /products?updated_since=2026-11-09T10:00:00Z
{ "data": [{
"id": 12, "name": "Cotton Panjabi", "slug": "cotton-panjabi", "description": "…", "status": "active",
"category": { "id": 2, "name": "Men" },
"options": [{ "name": "Size", "values": ["M", "L"] }],
"track_inventory": true,
"images": [{ "url": "https://…/media/…webp", "thumb_url": "https://…", "alt": "Cotton Panjabi", "width": 1600, "height": 1600 }],
"variants": [{ "id": 31, "title": "M", "options": ["M"], "sku": "PJ-M", "barcode": null,
"price": "2450.00", "compare_at_price": "2900.00", "stock": 7, "in_stock": true }],
"updated_at": "2026-11-09T11:42:10.120Z" }],
"page": 1, "per_page": 50, "total": 1, "has_more": false }
GET /products/:id — one product, same shape, as { "data": { … } }.
Haatly-managed: inventory
GET /inventory?sku=PJ-M,PJ-L or ?variant_id=31,32 — current stock for those variants. Without a filter, every variant, 100 per page. Use it right before checkout to show "only 2 left".
{ "data": [{ "variant_id": 31, "product_id": 12, "sku": "PJ-M", "stock": 7, "in_stock": true, "track_inventory": true, "updated_at": "…" }] }
stock is null for products that don't track inventory (always in stock).
Haatly-managed: orders
Send an order — POST /orders
Send it when the customer places it. Haatly reserves the stock straight away and the order appears in the dashboard. Items match by sku (recommended) or variant_id.
POST /orders
{
"external_id": "WC-10045", // your order id — required, unique per connection
"status": "pending", // or "confirmed"
"customer": { "name": "Nusrat Jahan", "phone": "+8801712345678", "email": null,
"address": "House 12, Road 4, Mirpur 10", "area": "Mirpur", "district": "Dhaka" },
"items": [{ "sku": "PJ-M", "quantity": 2 }, { "sku": "BELT-01", "quantity": 1, "unit_price": "600.00" }],
"delivery_charge": 60,
"discount": 0,
"payment": { "method": "bkash", "status": "paid" }, // cod · bkash · nagad · sslcommerz · bank · cash · other
"note": "Call before delivery"
}
Safe to retry. Sending the same external_id again returns the existing order with 200 and Idempotent-Replayed: true instead of creating a duplicate — so after a timeout, just send it again. A new order returns 201. unit_price is optional (Haatly's price is used); phone numbers are normalised to 01XXXXXXXXX.
201 Created
{ "data": { "id": 88, "number": 1042, "external_id": "WC-10045", "source": "woocommerce", "status": "pending",
"customer": { … }, "shipping": { … }, "items": [ … ],
"subtotal": "5500.00", "discount": "0.00", "delivery_charge": "60.00", "total": "5560.00",
"payment": { "method": "bkash", "status": "paid", "paid_amount": "5560.00" },
"courier": null, "placed_at": "…", "updated_at": "…" } }
Read orders
GET /orders/:external_id — status, payment and courier tracking. GET /orders?updated_since=…&status=shipped — orders from this connection, newest first, paged.
Cancel — POST /orders/:external_id/cancel
Body { "reason": "Customer cancelled" }. Stock goes back. Only before it ships — after that you get 409 cannot_cancel.
Record a payment — POST /orders/:external_id/payments
Body { "amount": 500, "method": "sslcommerz" } — e.g. when an advance or online payment completes after the order was sent.
Webhooks
If the connection has a webhook address, Haatly POSTs JSON to it when something changes:
| Event | When | data |
|---|---|---|
order.created | An order was added in Haatly or by another site | { order } |
order.updated | Status, payment, shipping or courier tracking changed | { order } |
product.updated | Details, prices, images or status changed | { products: [ … ] } |
inventory.updated | Stock changed — orders, cancellations, returns, manual adjustments, imports | { inventory: [ … ] } |
ping | "Send test event" in the dashboard | { message } |
store.command | The owner asked this store to do something (always sent to that store, no subscription needed) | { command } |
POST https://yourshop.com/haatly/webhook
X-Haatly-Event: inventory.updated
X-Haatly-Delivery: 01JC8Z3R4W6Y8A0C2E4G6J8K9M
X-Haatly-Signature: t=1794234904,v1=5f2b…c9
{ "id": "01JC8Z3R4W6Y8A0C2E4G6J8K9M", "type": "inventory.updated", "created_at": "2026-11-09T14:35:05.012Z",
"data": { "inventory": [{ "variant_id": 31, "sku": "PJ-M", "stock": 5, "in_stock": true, … }] } }
Answer with any 2xx within 10 seconds. Anything else is retried with growing gaps (about 30 s, 1, 2, 4 and 8 minutes). Deliveries can arrive more than once or out of order: use id to skip repeats, and for stock, trust the number in the newest event (or re-read /inventory).
Check the signature
v1 is HMAC-SHA256 of "<t>.<raw body>" with your signing secret. Use the raw request body, compare in constant time, and reject timestamps older than 5 minutes.
// Node.js (Express: app.post('/haatly/webhook', express.raw({ type: 'application/json' }), handler))
import { createHmac, timingSafeEqual } from 'node:crypto';
function verify(secret, rawBody, header) {
const { t, v1 } = Object.fromEntries(header.split(',').map((p) => p.split('=')));
if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex');
return v1?.length === expected.length && timingSafeEqual(Buffer.from(v1), Buffer.from(expected));
}
// PHP (WordPress / WooCommerce)
$raw = file_get_contents('php://input');
parse_str(str_replace(',', '&', $_SERVER['HTTP_X_HAATLY_SIGNATURE'] ?? ''), $sig);
$expected = hash_hmac('sha256', $sig['t'] . '.' . $raw, HAATLY_WEBHOOK_SECRET);
if (abs(time() - (int) $sig['t']) > 300 || !hash_equals($expected, $sig['v1'] ?? '')) { http_response_code(401); exit; }
Recommended sync flow
- First run: page through
GET /products?status=alland create or update the site's products by SKU. - Keep in step: handle
product.updatedandinventory.updatedwebhooks. As a safety net, every 15 minutes callGET /products?updated_since=<last run>. - Checkout: optionally check
GET /inventory?sku=…, thenPOST /ordersas soon as the order is placed. On409 out_of_stock, tell the customer and refresh stock. - After checkout: show the customer the status and courier tracking from
order.updatedwebhooks orGET /orders/:external_id. - Cancellations on the site:
POST /orders/:external_id/cancelso the stock comes back everywhere.
Haatly is the source of truth for products, prices and stock. Edit them in Haatly, not on the site, or the next sync will overwrite the site's change.