Labeeny Delivery API
Order Labeeny deliveries for your customers from your own system: get a price, place the order, follow it as the captain moves, and cancel it if needed.
Everything after login is GraphQL: one endpoint, POST requests with a
JSON body {"query": "…", "variables": {…}}.
1. Before you start
Your customer's app ──► Your backend ──► Labeeny API
◄── ◄── (webhooks)
Your client secret, your API token and your webhook secret stay on your server. Never put them in:
- a website, a mobile app, or anything else that runs on a customer's device;
- a source repository, a build file, a log line or an error report.
An API token can read and change every order your account has created, for all of your customers. Your backend decides which customer sees which order.
Endpoint
Everything, login included, goes to one GraphQL endpoint. Only order files (3.3) download from storage:
| Name | URL |
|---|---|
GRAPHQL_URL | |
STORAGE_URL | |
You also need a phone number for your account. It receives the sign-in codes by SMS: use a number your team keeps, not a person's who may leave.
2. Setup
Done once by a developer on your team. Steps 1 and 2 take a few minutes on the account page; only step 3 runs in your backend.
- Create your API account and have Labeeny approve it.
- Create API credentials: a client id and secret for your backend.
- Log in as the API user from your backend, whenever a token expires.
2.1 Create your API account
Open the account page, choose Create account, enter your company name and phone, and type the code we send by SMS.
account_not_approved. The account page shows when you're approved.
2.2 Create API credentials
On the account page, under API credentials, name the credential (for example Production backend) and create it.
- The secret is shown only once. We keep only a hash of it. Lost it? Create a new credential and revoke the old one.
- Store it in your backend's secret store (your cloud's secret manager, or an environment variable of the server process). Never in an app, a repository or a log.
- One credential per environment (production, staging…), named so you can tell them apart. You can hold up to 5 active credentials.
Rotating without downtime: create a new credential, deploy it to your backend, check its last used time is moving, then revoke the old one. Tokens already issued with the old one keep working until they expire (up to 1 hour).
2.3 Log in from your backend
The only step your backend repeats: exchange the credential for an API token with
the loginClient mutation. Send it with no Authorization
header.
mutation Login {
loginClient(clientId: "cid_…", clientSecret: "csk_…") {
accessToken
token_type
expiresIn
}
}
{"data": {"loginClient": {"accessToken": "eyJ…", "token_type": "Bearer", "expiresIn": 3600}}}
Send the token on every other GraphQL request:
POST {GRAPHQL_URL}
Authorization: Bearer eyJ…
Content-Type: application/json
- The token lasts 1 hour. Keep one per credential in your backend's memory,
shared by all requests, and log in again shortly before it expires or when a request answers
invalid-jwt/JWTExpired. Don't log in for every request. - Your defaults ride in the token (3.0): after changing them, they apply from the next login.
A minimal token cache, in Node.js:
let cached = null; // {token, expiresAt}
async function labeenyToken() {
const stillValid = cached && Date.now() < cached.expiresAt - 60_000;
if (stillValid) return cached.token;
const response = await fetch(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}`);
const {accessToken, expiresIn} = data.loginClient;
cached = {token: accessToken, expiresAt: Date.now() + expiresIn * 1000};
return accessToken;
}
async function labeeny(query, variables = {}) {
const response = await fetch(GRAPHQL_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${await labeenyToken()}`,
},
body: JSON.stringify({query, variables}),
});
const {data, errors} = await response.json();
if (errors) throw new Error(errors[0].message);
return data;
}
| Error | Meaning |
|---|---|
invalid_request | clientId or clientSecret is empty. |
invalid_client | Wrong id or secret. |
account_not_approved | Labeeny hasn't approved your account yet (2.1). Contact us. |
client_disabled | The credential is revoked, or Labeeny switched the account off. |
default_vehicle_inactive | Your default vehicle type is no longer offered. Change it (3.0), then log in again. |
3. The flow
All of these are GraphQL requests sent with the API token from 2.3.
3.0 Optional: set defaults
If you usually ship from one place, or always with the same vehicle, save them once on the account page under Defaults and leave them out of your estimates. Your backend's API token can't change them.
- Default pickup: used when an estimate has no
pickup. Apickupsent with an estimate replaces it completely, address included. - Default pickup phone: used when an order has no
pickup_phone(3.2). - Default vehicle: used when an estimate has no
vehicle_type. Without one, the delivery goes bymotorcycle. - New defaults apply from your next login: your current token keeps the old ones until it expires.
3.1 Get a price: estimateDelivery
Send the customer and both ends of the trip, and get the price to show your customer. The customer is identified by phone: you don't create customers or keep customer ids.
mutation Estimate {
estimateDelivery(
customer: {name: "Rami Haddad", phone: "0933123456"}
pickup: {lat: 36.2021, lng: 37.1343, address: "محل ١٢، العزيزية"}
dropoff: {lat: 36.2105, lng: 37.1550, address: "بناء ٤، الطابق الثاني"}
order_type: "transport"
vehicle_type: "motorcycle"
) {
estimate_id
expires_at
currency
total_price
price_breakdown
distance_meters
duration_seconds
vehicle_type
}
}
Request
| Field | Required | Notes |
|---|---|---|
customer.name | yes | Names the customer the first time we see this phone. A customer we already know keeps their name; to show another name on one order, send customer_name in 3.2. |
customer.phone | yes | The customer's Syrian mobile, in any of these forms: 0933123456, +963933123456, 963933123456. The captain calls this number. |
pickup | if no default | Where the captain collects the item. Leave it out to use your default pickup (3.0). |
pickup.lat, pickup.lng | with pickup | Decimal degrees. |
pickup.address | recommended | Shown to the captain: shop name, street, landmark. Write it in Arabic. |
dropoff.lat, dropoff.lng | yes | The customer's location, in decimal degrees. |
dropoff.address | recommended | Building, floor, landmarks, in Arabic. |
order_type | no | What the captain does (below). Default transport. |
vehicle_type | no | One of the vehicle types listed under Defaults on the account page, for example motorcycle. Default: your default vehicle, else motorcycle. |
Order types
| Type | The captain… |
|---|---|
transport | collects an item at the pickup and delivers it to your customer. |
pickup_shop | collects goods that are already paid for from a shop, and delivers them. |
deliver_collect | delivers, and collects the item's price from your customer in cash on arrival. Needs item_cost on the order (3.2). |
Response
{
"data": {
"estimateDelivery": {
"estimate_id": "8f14e45f-ceea-4c3b-9b1a-2f5c1e0b7a11",
"expires_at": "2026-11-18T10:10:00.000Z",
"currency": "SYP",
"total_price": 15000,
"price_breakdown": [
{"title": "base_fare", "amount": 5000},
{"title": "distance_cost", "amount": 10000}
],
"distance_meters": 3120,
"duration_seconds": 540,
"vehicle_type": "motorcycle"
}
}
}
| Field | Meaning |
|---|---|
estimate_id | Send it to createDelivery to order at this price. |
expires_at | The price is valid until then: 10 minutes. After that, ask for a new estimate. |
total_price | What the delivery costs, in currency (Syrian pounds, SYP). This is the number to show and charge. |
price_breakdown | The parts of the price, each {title, amount}, if you want to show them. They add up to total_price; which rows appear can change, so don't rely on specific titles. |
distance_meters, duration_seconds | The expected route length and driving time from pickup to drop-off. |
vehicle_type | The vehicle the price is for. |
- Prices are the standard fare. Labeeny promotions and coupons don't apply to API orders.
- An estimate costs nothing and commits to nothing: ask for as many as you need.
- Errors:
invalid-customer-phone,customer-name-required,pickup-required,invalid-location,invalid-order-type,invalid-vehicle-type(see 6).
3.2 Place the order: createDelivery
When your customer accepts the price, place the order. The price, the trip, the customer and the vehicle all come from the estimate: you can't change them here.
mutation Create {
createDelivery(
estimate_id: "8f14e45f-ceea-4c3b-9b1a-2f5c1e0b7a11"
external_reference: "ORDER-1042"
notes: "Fragile, call on arrival"
customer_name: "Rami Haddad"
pickup_phone: "0944000111"
) {
order_id
}
}
{"data": {"createDelivery": {"order_id": "c9f0f895-fb98-4b7a-9d3e-5a1e2c4b6d70"}}}
Request
| Field | Required | Notes |
|---|---|---|
estimate_id | yes | From 3.1: yours, not expired and not used for another order. One estimate makes one order. |
external_reference | yes | Your own id for this order, any format, up to 50 characters (spaces at either end are removed). It comes back in every webhook and query, and makes retries safe (below). It must be unique among your orders that aren't cancelled. |
notes | no | Shown to the captain: what to watch out for, who to ask for. |
customer_name | no | The name shown to the captain on this order. Leave it out to use the customer's name (3.1). |
pickup_phone | no | Who the captain calls at the pickup point, as a Syrian number: 0944000111 or +963944000111. Leave it out to use your default pickup phone. |
item_cost | for deliver_collect | The amount the captain collects from your customer, in SYP, as a number (25000, not "25000"), zero or more. Required for deliver_collect orders, refused for the others. |
scheduled_for | no | Book the delivery for later: a date and time with its time zone, such as "2026-11-21T09:30:00+03:00", in the future and at most 7 days ahead. Leave it out to deliver now. |
Scheduled deliveries
- The price is the estimate's, fixed when you book. The order stays
pending_acceptanceuntil shortly beforescheduled_for(about 30 minutes), when Labeeny starts looking for a captain. - You receive
order.createdwhen you book. Your customer is told once a captain accepts, not before. - You can cancel any time until a captain accepts, then for 2 minutes (3.4).
scheduled_forcomes back in webhooks and queries.
What happens next
- The order starts as
pending_acceptance: Labeeny is finding a captain. - Your webhook receives
order.created(3.3). - Your customer becomes a Labeeny customer under their phone, and can follow the order in the Labeeny app if they have it (5).
createDelivery times out or fails on the
network, send it again with the same estimate_id and external_reference:
you get the same order_id back, even after the price has expired, and no second delivery
is created.
- The same
external_referencewith a differentestimate_idis refused (external-reference-in-use): it would be a second order under the same id. - Once an order is cancelled, its
external_referenceis free again, so you can re-order under the same id with a new estimate. A delivered order keeps its reference. - Errors:
estimate-not-found,external-reference-required,external-reference-too-long,external-reference-in-use,item-cost-required,item-cost-not-applicable,item-cost-invalid,invalid-pickup-phone,invalid-scheduled-for,scheduled-for-in-past,scheduled-for-too-far(see 6).
3.3 Follow the order
Webhooks tell you when an order changes; queries give you its full state at any time. Use both: webhooks for speed, a query as a fallback.
Webhooks (recommended)
Set your URL once on the account page under Webhook. Your backend's API token can't change it, so a leaked token can't redirect your order events.
- The URL must be
httpsand reachable on the public internet. URLs with a username or password in them, private or local addresses (localhost,10.x,192.168.x…) and Labeeny's own domains are refused. - Saving it sends a test
pingand shows your webhook secret (lab_…) once. Store it next to your client secret: you need it to check our signatures. - Saving again replaces the URL and issues a new secret. The old one stops working at once.
- Redirects aren't followed: answer at the URL itself, with any
2xxstatus.
We POST JSON to your URL on every change:
{
"id": "evt_7d0…",
"type": "order.status_changed",
"created_at": "2026-11-07T10:00:00Z",
"data": {
"order_id": "…",
"external_reference": "YOUR-ORDER-1042",
"status": "on_way",
"previous_status": "accepted_by_driver",
"price": 15000,
"currency": "SYP",
"captain": {"name": "Ahmad", "phone": "0955…"},
"cancel_reason": null,
"cancelled_by_role": null
}
}
Event types: order.created, order.status_changed,
order.cancelled, ping.
Check the signature on every request. The Labeeny-Signature header
looks like t=1762509600,v1=5f2c…: an HMAC-SHA256 of {t}.{raw body} with
your webhook secret. In Node.js:
const crypto = require("crypto");
function isFromLabeeny(signatureHeader, rawBody, webhookSecret) {
const parts = Object.fromEntries(signatureHeader.split(",").map((part) => part.split("=")));
const expected = crypto.createHmac("sha256", webhookSecret)
.update(`${parts.t}.${rawBody}`)
.digest("hex");
const sameLength = parts.v1?.length === expected.length;
const signatureMatches = sameLength &&
crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
const isRecent = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;
return signatureMatches && isRecent;
}
Use the raw request body, before any JSON parsing.
- Reply with
2xxwithin 5 seconds. Do slow work after you've replied. - Use
idto ignore duplicates. - In v1 a webhook is sent once, with no retries. Also poll (below) for orders that haven't changed for a while.
Querying
query Order($id: uuid!) {
orders_by_pk(id: $id) {
id external_reference status status_updated_at
price currency order_type
pickup_address dropoff_address
captain { displayName avatarUrl phoneNumber }
captain_location
order_files { type file_id } # the captain's photos: see Order files
customer_name dropoff_phone_number
created_at accepted_at delivered_at
cancel_reason cancelled_by_role
scheduled_for
}
}
query MyActiveOrders {
orders(
where: {status: {_in: ["pending_acceptance", "accepted_by_driver", "on_way", "picked_up", "in_transit"]}}
order_by: {created_at: desc}
limit: 50
) { id external_reference status customer_name }
}
captainis set while a captain is on the order and it isn't cancelled or delivered; otherwisenull.- Live position: webhooks report status changes, not the captain's movement.
To show the captain on a map, poll
captain_location({lat, lng, updated_at}) every 15 seconds while the order ison_way,picked_uporin_transit, and stop once it isn't. Don't poll more often than that. It'snullotherwise. - You can read only the orders you created. Filter by customer with
where: {dropoff_phone_number: {_eq: "0933123456"}}, or by your own id withwhere: {external_reference: {_eq: "YOUR-ORDER-1042"}}.
Order files
The captain photographs the item when they collect it and when they hand it over. Each photo
is a row in order_files:
type | What it is | When it appears |
|---|---|---|
pickup_proof | The item, photographed at pickup. | around picked_up |
delivery_proof | The item, photographed at your customer's door. | around delivered |
1. List them with the order. Ask for the two types by name, so a type added later doesn't surprise your code:
query OrderPhotos($id: uuid!) {
orders_by_pk(id: $id) {
order_files(where: {type: {_in: ["pickup_proof", "delivery_proof"]}}) {
type
file_id
}
}
}
2. Download each one from storage, with the same token as your GraphQL requests:
GET {STORAGE_URL}/files/{file_id}
Authorization: Bearer eyJ…
async function downloadOrderFile(fileId) {
const response = await fetch(`${STORAGE_URL}/files/${fileId}`, {
headers: {"Authorization": `Bearer ${await labeenyToken()}`},
});
if (!response.ok) throw new Error(`Labeeny file ${fileId}: ${response.status}`);
return {
contentType: response.headers.get("content-type"), // for example "image/jpeg"
bytes: Buffer.from(await response.arrayBuffer()),
};
}
- The answer is the file itself. Read its format from the
Content-Typeheader. - Need the format or size first? Ask GraphQL:
file(id: "…") { mimeType size createdAt }. - You can read only the files of orders you created. Any other file answers
403or404. - A photo can be missing or arrive late: list the files again later instead of expecting both.
- Don't give these URLs to your customers' apps: they need your token. Download in your backend, then serve the photo or keep a copy.
- Webhooks don't announce files. Read
order_fileswhen you receivepicked_upordelivered.
3.4 Cancel: cancelOrder
mutation { cancelOrder(orderId: "…", reason: "CHANGED_MIND", notes: "Customer not home") { success message } }
- Allowed while the order is waiting for a captain, and up to 2 minutes after a captain accepts it. After that, contact Labeeny support.
- Delivered or already-cancelled orders can't be cancelled (
409). reason: one ofCHANGED_MIND,MISTAKE,DRIVER_LATE,HIGH_WAIT_TIME,BETTER_PRICE,BAD_LOCATION,OTHER.- Only you can cancel. Your customer can't cancel the order in the Labeeny app:
they contact you, and you call
cancelOrder.
4. Order statuses
| Status | Meaning |
|---|---|
pending_acceptance | Placed, looking for a captain. |
accepted_by_driver | A captain accepted. The 2-minute cancellation window starts. |
on_way | The captain is heading to the pickup. Captain details are available. |
picked_up | The captain has the item. |
in_transit | On the way to the customer. |
delivered | Done. Final. |
cancelled | Cancelled by you, Labeeny, the captain, or because no captain was found. Final. cancelled_by_role and cancel_reason say which. |
accepted_by_driver or on_way to
pending_acceptance if the captain drops it and we reassign it. Handle any status
arriving in any order.
5. Your customers' data
- Your customer becomes a Labeeny customer under their phone number. If they sign in to the Labeeny app with it, they see the orders you sent them, labelled with your name, and can follow the captain there. They can't cancel them.
- You see only what you sent us about a customer (name and phone, on each order). You never see whether they already used Labeeny, or any of their other orders.
- We don't text your customer in this version: tell them about the order yourself. If they have the Labeeny app, they get its usual notifications. The captain may call the customer's phone.
- Captain contact details and position are given only while a delivery is in progress. Use them only for that delivery.
6. Errors
GraphQL errors come back with HTTP 200 as
{"errors": [{"message": "…", "extensions": {…}}]}, as in any GraphQL API. Check
errors on every response.
| Message | Meaning |
|---|---|
pickup-required | No pickup in the request and no default pickup set. |
estimate-not-found | The estimate_id is wrong, expired (more than 10 minutes old), already used for an order, or not yours. Ask for a new estimate. |
invalid-customer-phone | The customer phone isn't a valid number, or can't be used for a customer (for example, it belongs to a Labeeny captain). |
customer-name-required | customer.name is empty. |
invalid-location | pickup or dropoff is missing lat/lng, or they're out of range. |
invalid-order-type | order_type isn't transport, pickup_shop or deliver_collect. |
invalid-vehicle-type | The vehicle_type, or your default vehicle, isn't one Labeeny currently offers. |
item-cost-required / item-cost-not-applicable | item_cost and order_type don't match. |
item-cost-invalid | item_cost isn't a number of zero or more. |
invalid-pickup-phone | pickup_phone isn't a valid Syrian phone number. |
invalid-scheduled-for | scheduled_for isn't a date and time. |
scheduled-for-in-past | scheduled_for is now or in the past. |
scheduled-for-too-far | scheduled_for is more than 7 days ahead. |
external-reference-required | createDelivery has no external_reference, or it's blank. |
external-reference-too-long | external_reference is longer than 50 characters. |
external-reference-in-use | You already have an order with this reference, made from a different estimate. A retry must send the same estimate_id; a new order needs a new reference. |
window-expired | Too late to cancel (more than 2 minutes after acceptance). |
not-your-order | You didn't create this order. |
invalid-webhook-url | The webhook URL isn't valid, has a username or password in it, or is too long. |
webhook-url-not-https | The webhook URL doesn't start with https://. |
webhook-url-not-public | The webhook URL points to a private or local address. |
webhook-url-not-allowed | The webhook URL points to Labeeny's own servers. |
webhook-host-not-found | The webhook host name doesn't resolve. Check for typos, or wait for new DNS to spread. |
config-not-found | Your API account isn't approved yet. Contact Labeeny. |
unable-to-create-estimate | We couldn't price this trip right now. Try again in a moment. |
internal-error | Something failed on our side. Retrying is safe; contact Labeeny if it keeps happening. |
invalid-jwt / JWTExpired | Log in again (2.3). |