Integration guide
Connect your backend to Labeeny in six steps. Each step has a curl example to try in a terminal and a Node.js example for your code.
Want it all in one place? The full example is a complete backend in one file, with proof photos and push notifications to your customer.
Before you start
- On the account page, create your account and wait for Labeeny to approve it.
- Create a credential there and copy its client id and client secret.
- Put them in your backend's environment, never in an app or in your code:
export GRAPHQL_URL=""
export STORAGE_URL="" # order photos (step 5)
export LABEENY_CLIENT_ID="cid_…"
export LABEENY_CLIENT_SECRET="csk_…"
1. Log in
Exchange your credential for a token with the loginClient mutation, sent with
no Authorization header. The token lasts 1 hour: keep it
and reuse it, and log in again only when it's about to expire.
curl -s "$GRAPHQL_URL" \
-H "Content-Type: application/json" \
--data @- <<EOF
{
"query": "mutation (\$id: String!, \$secret: String!) { loginClient(clientId: \$id, clientSecret: \$secret) { accessToken expiresIn } }",
"variables": {"id": "$LABEENY_CLIENT_ID", "secret": "$LABEENY_CLIENT_SECRET"}
}
EOF
# {"data": {"loginClient": {"accessToken": "eyJ…", "expiresIn": 3600}}}
export TOKEN="eyJ…" # paste it, for the next steps
// labeeny.js
let token = null;
let tokenExpiresAt = 0;
async function getToken() {
const oneMinute = 60 * 1000;
if (token && Date.now() < tokenExpiresAt - oneMinute) return token;
const response = await fetch(process.env.GRAPHQL_URL, {
method: "POST",
headers: {"Content-Type": "application/json"}, // no Authorization header to log in
body: JSON.stringify({
query: `mutation ($id: String!, $secret: String!) {
loginClient(clientId: $id, clientSecret: $secret) { accessToken expiresIn }
}`,
variables: {id: process.env.LABEENY_CLIENT_ID, secret: process.env.LABEENY_CLIENT_SECRET},
}),
});
const {data, errors} = await response.json();
if (errors) throw new Error(`Labeeny login failed: ${errors[0].message}`); // e.g. "invalid_client"
token = data.loginClient.accessToken;
tokenExpiresAt = Date.now() + data.loginClient.expiresIn * 1000;
return token;
}
// Every other call goes through this.
async function labeeny(query, variables) {
const response = await fetch(process.env.GRAPHQL_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${await getToken()}`,
},
body: JSON.stringify({query, variables}),
});
const {data, errors} = await response.json();
if (errors) throw new Error(errors[0].message); // e.g. "estimate-not-found"
return data;
}
module.exports = {labeeny};
An account_not_approved error means Labeeny hasn't approved your account yet.
2. Get a price
Send your customer and where the delivery goes from and to. You get a price that is valid for 10 minutes: show it to your customer.
curl -s "$GRAPHQL_URL" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
--data @- <<'EOF'
{
"query": "mutation ($customer: ApiCustomerInput!, $pickup: ApiLocationInput, $dropoff: ApiLocationInput!) { estimateDelivery(customer: $customer, pickup: $pickup, dropoff: $dropoff) { estimate_id total_price currency expires_at } }",
"variables": {
"customer": {"name": "Rami Haddad", "phone": "0933123456"},
"pickup": {"lat": 36.2021, "lng": 37.1343, "address": "محل ١٢، العزيزية"},
"dropoff": {"lat": 36.2105, "lng": 37.1550, "address": "بناء ٤، الطابق الثاني"}
}
}
EOF
const {labeeny} = require("./labeeny");
const {estimateDelivery: estimate} = await labeeny(`
mutation ($customer: ApiCustomerInput!, $pickup: ApiLocationInput, $dropoff: ApiLocationInput!) {
estimateDelivery(customer: $customer, pickup: $pickup, dropoff: $dropoff) {
estimate_id total_price currency expires_at
}
}`, {
customer: {name: "Rami Haddad", phone: "0933123456"},
pickup: {lat: 36.2021, lng: 37.1343, address: "محل ١٢، العزيزية"},
dropoff: {lat: 36.2105, lng: 37.1550, address: "بناء ٤، الطابق الثاني"},
});
console.log(estimate.total_price, estimate.currency); // 15000 "SYP"
// Save estimate.estimate_id with your order: step 3 needs it.
{
"data": {
"estimateDelivery": {
"estimate_id": "8f14e45f-…",
"total_price": 15000,
"currency": "SYP",
"expires_at": "2026-11-18T10:10:00Z"
}
}
}
- Write addresses in Arabic: the captain reads them.
- Saved a default pickup on the account page? Leave
pickupout.
3. Place the order
When your customer accepts the price, create the delivery. Send your own order id
as external_reference.
curl -s "$GRAPHQL_URL" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
--data @- <<'EOF'
{
"query": "mutation ($estimateId: uuid!, $reference: String!) { createDelivery(estimate_id: $estimateId, external_reference: $reference) { order_id } }",
"variables": {"estimateId": "8f14e45f-…", "reference": "ORDER-1042"}
}
EOF
# {"data": {"createDelivery": {"order_id": "c9f0f895-…"}}}
const {createDelivery} = await labeeny(`
mutation ($estimateId: uuid!, $reference: String!, $notes: String) {
createDelivery(estimate_id: $estimateId, external_reference: $reference, notes: $notes) {
order_id
}
}`, {
estimateId: estimate.estimate_id,
reference: "ORDER-1042", // your order id
notes: "Fragile, call on arrival",
});
// Save createDelivery.order_id next to your order.
estimate_id and external_reference: you get the same
order_id, never a second delivery.
Got estimate-not-found? The price expired: go back to step 2 and show the new
price.
4. Get updates (webhooks)
Labeeny calls your backend every time a delivery changes. Add an endpoint, then save its URL on the account page: you get a webhook secret to check that calls really come from Labeeny.
Here's what arrives:
{
"id": "evt_7d0…",
"type": "order.status_changed",
"created_at": "2026-11-18T10:05:00Z",
"data": {
"order_id": "c9f0f895-…",
"external_reference": "ORDER-1042",
"status": "on_way",
"captain": {"name": "Ahmad", "phone": "0955…"}
}
}
And a Node.js (Express) endpoint for it:
const crypto = require("crypto");
const express = require("express");
const app = express();
function isFromLabeeny(signature, rawBody) {
// signature looks like "t=1763460300,v1=5f2c…"
const {t, v1} = Object.fromEntries(signature.split(",").map((part) => part.split("=")));
const expected = crypto
.createHmac("sha256", process.env.LABEENY_WEBHOOK_SECRET)
.update(`${t}.${rawBody}`)
.digest("hex");
return v1?.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(v1), Buffer.from(expected));
}
// express.raw: the signature is checked on the body exactly as it arrived.
app.post("/labeeny/webhook", express.raw({type: "application/json"}), (req, res) => {
const rawBody = req.body.toString();
if (!isFromLabeeny(req.get("Labeeny-Signature") ?? "", rawBody)) return res.sendStatus(401);
const event = JSON.parse(rawBody);
res.sendStatus(200); // answer within 5 seconds, then do the work
if (event.type === "ping") return;
console.log(event.data.external_reference, "is now", event.data.status);
// Update your order, notify your customer…
});
| Event | When |
|---|---|
order.created | The order is placed; Labeeny is finding a captain. |
order.status_changed | A captain accepted, set off, picked up, is on the way, delivered. |
order.cancelled | The order was cancelled. |
ping | A test, when you save the webhook URL. |
- The same event can arrive twice: skip an
idyou've already handled. - Each event is sent once, with no retries. If your endpoint was down, step 5 catches you up.
5. Check an order
Read an order at any time: to show its status, catch up on a missed webhook, or show the captain
on a map (captain_location, while the captain is on the way: poll it every
15 seconds).
curl -s "$GRAPHQL_URL" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
--data @- <<'EOF'
{
"query": "query ($id: uuid!) { orders_by_pk(id: $id) { status external_reference captain { displayName phoneNumber } captain_location } }",
"variables": {"id": "c9f0f895-…"}
}
EOF
const {orders_by_pk: order} = await labeeny(`
query ($id: uuid!) {
orders_by_pk(id: $id) {
status external_reference
captain { displayName phoneNumber }
captain_location
}
}`, {id: "c9f0f895-…"});
console.log(order.status); // "on_way"
| Status | Meaning |
|---|---|
pending_acceptance | Looking for a captain. |
accepted_by_driver | A captain accepted. |
on_way | The captain is going to the pickup. |
picked_up | The captain has the item. |
in_transit | On the way to your customer. |
delivered | Done. |
cancelled | Cancelled. |
Proof photos
The captain photographs the item at pickup (pickup_proof) and at your customer's
door (delivery_proof). List them with the order, then download each one from
STORAGE_URL with the same token.
curl -s "$GRAPHQL_URL" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
--data @- <<'EOF'
{
"query": "query ($id: uuid!) { orders_by_pk(id: $id) { order_files(where: {type: {_in: [\"pickup_proof\", \"delivery_proof\"]}}) { type file_id } } }",
"variables": {"id": "c9f0f895-…"}
}
EOF
# {"data": {"orders_by_pk": {"order_files": [{"type": "delivery_proof", "file_id": "6f1c…"}]}}}
curl -s "$STORAGE_URL/files/6f1c…" \
-H "Authorization: Bearer $TOKEN" \
-o delivery_proof.jpg
const {orders_by_pk: order} = await labeeny(`
query ($id: uuid!) {
orders_by_pk(id: $id) {
order_files(where: {type: {_in: ["pickup_proof", "delivery_proof"]}}) { type file_id }
}
}`, {id: "c9f0f895-…"});
for (const file of order.order_files) {
const response = await fetch(`${process.env.STORAGE_URL}/files/${file.file_id}`, {
headers: {"Authorization": `Bearer ${await getToken()}`},
});
const photo = Buffer.from(await response.arrayBuffer());
// response.headers.get("content-type") is the format, for example "image/jpeg"
}
Read them when you receive picked_up or delivered: a photo can arrive a
little after the status. Download in your backend and serve the photo yourself, because the
download needs your token. More in the reference.
6. Cancel
You can cancel while Labeeny is looking for a captain, and up to 2 minutes after one accepts. Your customer can't cancel in the Labeeny app: they ask you.
curl -s "$GRAPHQL_URL" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
--data @- <<'EOF'
{
"query": "mutation ($orderId: uuid!) { cancelOrder(orderId: $orderId, reason: \"CHANGED_MIND\") { success message } }",
"variables": {"orderId": "c9f0f895-…"}
}
EOF
await labeeny(`
mutation ($orderId: uuid!, $reason: String!) {
cancelOrder(orderId: $orderId, reason: $reason) { success message }
}`, {orderId: "c9f0f895-…", reason: "CHANGED_MIND"});
Too late? You get window-expired: contact Labeeny support.
Every field and error is in the reference.