Truck Management (Owner)
How an owner creates a food truck, opens it for service with live GPS, promotes it, and triages reviews, including the asynchronous paid-feature state.
This guide is for Flutter engineers building the owner app. Every call here lives under /api/v1/owner/*, requires an Authorization: Bearer <oat_...> header, and the account must hold an active owner capability membership (otherwise you get 403 FORBIDDEN). Responses always use the standard envelope: { "data": <payload>, "meta": { "requestId": "req_..." } } on success, { "error": { "code", "message" }, "meta": {...} } on failure.
Send Accept-Language: ar for Arabic error/notification copy. Wire timestamps are always UTC ISO-8601 with Z; pass X-Timezone: Asia/Riyadh only when you need server-rendered display strings.
Creating a truck makes it live — there is no "publish after create" step. POST /api/v1/owner/trucks writes status=active and stamps publishedAt in the same request. The truck is in customer discovery the instant the 201 returns. Do not call POST /api/v1/owner/trucks/:id/publish after creating — on an already-active truck it just returns published: false. The publish endpoint only matters in the rare case a truck somehow sits in draft (the current create path never produces one).
The asynchronous state to account for is the paid feature flow, not publishing — see the feature flow below.
Three Independent Flags
These flags are independent and should be modeled separately:
| Flag | Controls | Default after create | Flipped by |
|---|---|---|---|
status=active | Whether the truck is discoverable in customer search | active (live immediately) | create / publish / admin moderation |
isOpen | Whether the truck shows as currently serving right now | false | owner toggle via PATCH + GPS |
isFeatured | Paid ranking boost | false | Paymob webhook after payment settles |
A brand-new truck is active (discoverable) but isOpen=false (not serving) and isFeatured=false (not promoted). Opening it and featuring it are separate, explicit actions.
The flow at a glance
Step 1 — Authenticate as an owner
Send Authorization: Bearer <oat_...> on every call. The token's account must have an active owner membership or every endpoint returns 403 FORBIDDEN.
Step 2 — Upload photos first
POST /api/v1/uploads with purpose=truck_photo to get fileIds. Do this before creating or updating the truck — you pass the ids in the truck body.
Step 3 — Create the truck (goes live)
POST /api/v1/owner/trucks. Send the optional full openingHours week and up to 10 ordered fileIds. Returns 201 with status=active, publishedAt stamped, isOpen=false, isFeatured=false. It is now discoverable.
Step 4 — Read it back
GET /api/v1/owner/trucks (your trucks, newest-first) or GET /api/v1/owner/trucks/:id (full detail incl. openingHours).
Step 5 — Edit anytime
PATCH /api/v1/owner/trucks/:id. Partial. Both fileIds and openingHours, when supplied, are full replacement sets. Omit either field to leave that collection unchanged.
Step 6 — Open for service (requires GPS)
PATCH /api/v1/owner/trucks/:id with isOpen:true and currentLat/currentLng. Those coords anchor drift detection.
Step 7 — Heartbeat while open
POST /api/v1/owner/trucks/:id/heartbeat with device lat/lng every ~60s. The server auto-closes the truck if it drifts past the threshold (default 150m). Read the response — the close is silent unless you do.
Step 8 — Share the live spot (optional)
POST /api/v1/owner/trucks/:id/location/share-link returns a short shareUrl (/t/:token) safe to paste into WhatsApp/SMS.
Step 9 — Promote (paid, pending → live via webhook)
POST /api/v1/owner/trucks/:id/feature creates a pending payment order + clientSecret. The truck does not become featured until the Paymob webhook settles. Re-fetch after the payment sheet closes.
Step 10 — Triage reviews
GET /api/v1/owner/trucks/:id/reviews shows all persisted review statuses; POST /api/v1/owner/reviews/:reviewId/report flags abuse.
Step 11 — Delete / restore
DELETE /api/v1/owner/trucks/:id soft-deletes; POST /api/v1/owner/trucks/:id/restore undoes it — but only if you were the deleter.
Step detail
Step 2 — Upload photos
Photos are uploaded separately and referenced by fileId. Multipart, capped at 10 photos per truck, 5 MB each (jpg/png/webp).
POST /api/v1/uploads
Authorization: Bearer oat_xxx
Content-Type: multipart/form-data
purpose=truck_photo
entityId=<truck id once it exists, or omit on first create then PATCH later>
[email protected]{
"data": {
"fileId": "fil_01jq8z5a0b1c2d3e4f5g6h7j8k",
"urls": { "original": "https://...", "thumb": "https://..." }
},
"meta": { "requestId": "req_01jq..." }
}Collect the fileIds and pass them as fileIds on the create/update body.
Step 3 — Create the truck
name is required (2–200 chars); everything else is optional. The optional translations.ar block adds Arabic copy (English stays at top level and is required). contactPreferences accepts up to 3 of phone | whatsapp | chat. openingHours accepts up to seven unique days using 0=Sunday ... 6=Saturday and 24-hour HH:MM strings.
POST /api/v1/owner/trucks
Authorization: Bearer oat_xxx
Content-Type: application/json
Accept-Language: en
{
"name": "Crispy Cart",
"description": "Smash burgers and turkish coffee, on wheels.",
"categoryId": "cat_01jq8z2c4r6n8p0q2s4u6w8y0a",
"cuisineTypes": ["burgers", "coffee"],
"city": "Riyadh",
"region": "Riyadh",
"address": "Tahlia Street, near Boulevard",
"lat": 24.6877,
"lng": 46.7219,
"contactPhone": "+966555012345",
"whatsappNumber": "+966555012345",
"contactPreferences": ["whatsapp", "phone"],
"fileIds": ["fil_01jq8z5a0b1c2d3e4f5g6h7j8k"],
"openingHours": [
{ "day": 0, "isClosed": false, "opensAt": "09:00", "closesAt": "21:00" },
{ "day": 1, "isClosed": false, "opensAt": "09:00", "closesAt": "21:00" },
{ "day": 2, "isClosed": true, "opensAt": "09:00", "closesAt": "21:00" }
],
"translations": { "ar": { "name": "العربة المقرمشة", "description": "برجر وقهوة تركية" } }
}{
"data": {
"truck": {
"id": "trk_01jq8z9c4r6n8p0q2s4u6w8y0a",
"status": "active",
"publishedAt": "2026-06-21T09:14:02.000Z",
"isOpen": false,
"isFeatured": false,
"featuredUntil": null,
"langActual": "en",
"openingHours": [{ "day": 0, "isClosed": false, "opensAt": "09:00", "closesAt": "21:00" }],
"images": [
{
"id": "fil_...",
"purpose": "truck_photo",
"urls": {
"original": "https://...",
"thumb": "https://...",
"medium": "https://...",
"large": "https://..."
}
}
]
}
},
"meta": { "requestId": "req_01jq..." }
}The field name for photos is fileIds, not imageFileIds. The truck is active and
publishedAt is set the moment you get this 201 — it is already in customer search. There is no
draft stage in this path.
Step 5 — Edit the truck
All fields optional. fileIds is not additive — it replaces the entire photo set:
- Omit
fileIds→ photos untouched. "fileIds": []→ all photos detached."fileIds": ["fil_a", "fil_b"]→ exactly those two photos, in that order.
openingHours has the same replacement behavior:
- Omit
openingHours→ schedule untouched. "openingHours": []→ clear the schedule; publicisOpenfalls back to the live flag.- Supply days → replace the whole stored schedule. Duplicate days, malformed times, or
closesAt <= opensAton an open day return422.
translations.ar is additive. Ownership errors are 404-before-403: a non-existent id returns 404 NOT_FOUND; an existing truck you do not own returns 403 FORBIDDEN (ordered so the existence check cannot be used to probe other owners' trucks).
PATCH /api/v1/owner/trucks/trk_01jq8z9c4r6n8p0q2s4u6w8y0a
Authorization: Bearer oat_xxx
Content-Type: application/json
{
"description": "Now open Saturdays.",
"cuisineTypes": ["burgers", "coffee", "shawarma"],
"openingHours": [
{ "day": 0, "isClosed": false, "opensAt": "10:00", "closesAt": "22:00" },
{ "day": 6, "isClosed": false, "opensAt": "12:00", "closesAt": "23:00" }
]
}Step 6 — Open for service (GPS required)
To start serving, flip isOpen to true in the same PATCH that carries currentLat and currentLng. Those coordinates become the drift-detection anchor.
PATCH /api/v1/owner/trucks/trk_01jq8z9c4r6n8p0q2s4u6w8y0a
Authorization: Bearer oat_xxx
Content-Type: application/json
{ "isOpen": true, "currentLat": 24.6877, "currentLng": 46.7219 }Omitting the coords on a false → true transition fails:
{
"error": {
"code": "CONFLICT",
"message": "Send your current GPS coordinates (currentLat, currentLng) when opening the truck.",
"field": "currentLat"
},
"meta": { "requestId": "req_01jq..." }
}(The thrown error carries the override code MISSING_OPEN_LOCATION; it resolves to the canonical CONFLICT for display.) Sending isOpen:false closes the truck and clears the GPS anchor — no coords needed.
Step 7 — Heartbeat while open
While the truck is open, POST .../heartbeat with the device's live lat/lng roughly every 60 seconds. The server measures distance from the open-anchor; if it exceeds TRUCK_DRIFT_THRESHOLD_M (default 150m) it auto-closes the truck (isOpen → false), clears the anchor, and pushes a warning notification to the owner.
POST /api/v1/owner/trucks/trk_01jq8z9c4r6n8p0q2s4u6w8y0a/heartbeat
Authorization: Bearer oat_xxx
Content-Type: application/json
{ "lat": 24.6901, "lng": 46.7250 }{
"data": { "isOpen": false, "distanceM": 312, "autoClosed": true },
"meta": { "requestId": "req_01jq..." }
}The auto-close is invisible to your polling loop unless you read the heartbeat body. isOpen,
distanceM, and autoClosed in the response are the only synchronous signal — render the "you
moved out of position" state from them. There is no auto-reopen when the truck drifts back;
re-opening (Step 6) recaptures a fresh anchor. distanceM is null when the truck is already
closed or has no anchor.
Reposition (distinct from opening)
PUT /api/v1/owner/trucks/:id/location replaces where the truck is without touching isOpen or the open-anchor. This is the preferred mobile route. The older PATCH verb remains available for compatibility. Use this endpoint to correct the pin; use Step 6 to start serving.
PUT /api/v1/owner/trucks/trk_01jq8z9c4r6n8p0q2s4u6w8y0a/location
Authorization: Bearer oat_xxx
Content-Type: application/json
{ "lat": 24.7136, "lng": 46.6753, "address": "King Fahd Road, near Kingdom Centre" }The response contains data.truck in the same owner-truck shape plus a compact data.location. Ownership is enforced (403), missing ids return 404, and invalid coordinates return 422.
Step 8 — Share the live spot
Generates (or reuses) a short public token for the current location, safe for WhatsApp/SMS. Recipients resolve it anonymously at GET /t/:token (no auth, outside /api/v1). The truck must already have a location, or you get 409 — set one via create-with-lat/lng, PATCH .../location, or opening the truck. The token is reused across calls, not regenerated.
POST /api/v1/owner/trucks/trk_01jq8z9c4r6n8p0q2s4u6w8y0a/location/share-link
Authorization: Bearer oat_xxx{
"data": {
"shareToken": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
"shareUrl": "https://app.trackme.example/t/a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6"
},
"meta": { "requestId": "req_01jq..." }
}Step 9 — Promote the truck (paid feature)
POST .../feature with durationDays (1–90, required) and optional currencyCode (3-char, default SAR) returns 201 with a pending payment order and a clientSecret. The truck is not featured at this point. isFeatured and featuredUntil change only after the Paymob webhook settles and runs the activation handler.
The truck must be active — featuring a draft/suspended/soft-deleted truck returns 409 TRUCK_FEATURE_REQUIRES_ACTIVE.
POST /api/v1/owner/trucks/trk_01jq8z9c4r6n8p0q2s4u6w8y0a/feature
Authorization: Bearer oat_xxx
Content-Type: application/json
{ "durationDays": 14, "currencyCode": "SAR" }{
"data": {
"paymentOrder": {
"id": "pord_01jq...",
"orderNumber": "PO-2026-000412",
"status": "pending",
"totalAmountMinor": 14000,
"currencyCode": "SAR",
"gateway": "paymob",
"gatewayReference": "..."
},
"clientSecret": "csk_...",
"immediatelyActivated": false
},
"meta": { "requestId": "req_01jq..." }
}Do not mark the truck featured from the 201 response. Hand clientSecret to the native
Paymob SDK to open the payment sheet. After the sheet closes, re-fetch the truck (GET /api/v1/owner/trucks/:id) or poll the payment order — isFeatured changes asynchronously when
the gateway webhook lands, not when this call returns. See Payments for
the webhook settlement lifecycle.
Renew with POST /api/v1/owner/trucks/:id/feature-renew (same body/response). It requires a truck that has been featured at least once — otherwise 409. Renewals chain via renewed_from_id so unused days carry over, and still settle via the webhook.
Step 10 — Reviews
GET /api/v1/owner/trucks/:id/reviews returns the owner-facing feed (newest-first, ?limit= default 50, max 200). Unlike the public list, it includes every persisted review status (visible, reported, soft_deleted, images_removed) and exposes status + reportedCount so you can see moderation outcomes.
{
"data": {
"items": [
{
"id": "rev_01jq...",
"rating": 2,
"comment": "Spammy link in here.",
"status": "reported",
"reportedCount": 0,
"images": [],
"createdAt": "2026-06-20T18:02:00.000Z"
}
]
},
"meta": { "requestId": "req_01jq..." }
}Flag abuse with POST /api/v1/owner/reviews/:reviewId/report (body: reportType + optional description). Open reports are deduped per reporter/target and admins are notified. Returns 201 { reportId, status }.
Step 11 — Delete & restore
DELETE /api/v1/owner/trucks/:id soft-deletes (sets status=soft_deleted, records you as the deleter, detaches photos) and returns { "success": true }. It is hidden from every public surface but you can still see it.
POST /api/v1/owner/trucks/:id/restore undoes it — only if you were the original deleter. If an admin took the truck down, restore returns 403 TRUCK_RESTORE_FORBIDDEN and you must appeal via support.
Lifecycle
status is the discoverability axis; isOpen and isFeatured are orthogonal flags layered on top.
| State | Meaning | How you got here | What's allowed next |
|---|---|---|---|
active | Live and discoverable in customer search | Created (default), published from draft, or admin-restored | Edit, open/close, feature, delete |
draft | Not discoverable | Reachable only via the publish endpoint's draft → active path; owner-created trucks are not born here today | publish → active |
suspended | Hidden from public by admin moderation; you can still see/edit | Admin action (out of owner scope) | Edit only — cannot self-publish or restore out of it |
soft_deleted | Hidden from every public surface | DELETE by owner or admin | Owner-deleted → restore; admin-deleted → appeal via support |
isOpen=true | Currently serving; anchored to a GPS open-point | PATCH isOpen:true + GPS | Heartbeat, close, auto-close on drift |
isOpen=false | Not serving | Default, owner close, or drift auto-close | Open again (recaptures anchor) |
isFeatured=true | Paid ranking boost with featuredUntil expiry | Paymob webhook settled a /feature order | Renew, or expires/undoes to false |
isFeatured=false | No boost | Default, or after expiry/undo | /feature to start (truck must be active) |
Transitions
(none) → active— Owner —POST /api/v1/owner/trucks(status set toactive+publishedAtstamped in the same write).draft → active— Owner —POST /api/v1/owner/trucks/:id/publish(idempotent; only valid fromdraft;409 TRUCK_PUBLISH_FORBIDDENfrom suspended/archived/soft_deleted).active → soft_deleted— Owner —DELETE /api/v1/owner/trucks/:id.soft_deleted → active— Owner —POST /api/v1/owner/trucks/:id/restore(only if the owner was the original deleter; else403 TRUCK_RESTORE_FORBIDDEN).active isOpen:false → active isOpen:true— Owner —PATCH .../:idwithisOpen:true+currentLat/currentLng(anchors drift detection).active isOpen:true → active isOpen:false— Owner —PATCH .../:idwithisOpen:false(clears the anchor).active isOpen:true → active isOpen:false (autoClosed)— System (drift detection) —POST .../:id/heartbeatwhen distance from the anchor exceedsTRUCK_DRIFT_THRESHOLD_M(default 150m); also pushes a notification to the owner.isFeatured:false → isFeatured:true— Payment webhook (System) —POST .../:id/featurecreates a pending order; the activation handler flipsisFeatured+ setsfeaturedUntilonly after the Paymob webhook settles.isFeatured:true → isFeatured:true (extended)— Owner → webhook (System) —POST .../:id/feature-renew(chains viarenewed_from_id; still settles via webhook).active → suspended— Admin (out of owner scope) — moderation; the owner sees the reason but cannot reverse it.
Implementation Notes
| Integration issue | Correct handling |
|---|---|
Calling publish after create to "go live" | Do not. Create already sets status=active + publishedAt. publish only transitions draft → active; on an active truck it returns published: false. |
Treating status=active as "open for orders" | active = discoverable in search. isOpen = currently serving. A new truck is active but isOpen=false until you explicitly open it. |
Opening with isOpen:true but no coordinates | Send currentLat and currentLng on the false → true transition or you get 409 MISSING_OPEN_LOCATION (field currentLat). Those coords are the drift anchor. |
Assuming the truck is featured after the /feature 201 | It is a pending payment order. isFeatured flips only after the Paymob webhook settles. Re-fetch the truck or poll the payment order after the sheet closes; immediatelyActivated is false. |
| Featuring a non-active truck | /feature returns 409 TRUCK_FEATURE_REQUIRES_ACTIVE for draft/suspended/soft_deleted. Get the truck active first. |
| Heartbeat loop never notices the auto-close | Read isOpen / autoClosed / distanceM from each heartbeat response. The server may flip isOpen → false mid-session past 150m; there is no auto-reopen — call open again to recapture an anchor. |
Expecting restore to work after an admin takedown | restore only works if you soft-deleted the truck. Admin-deleted (or suspended) trucks return 403 TRUCK_RESTORE_FORBIDDEN — appeal via support. |
Sending fileIds expecting it to append photos | fileIds is a full replacement set on PATCH. Omit to keep current photos; send [] to clear all. Upload first via POST /api/v1/uploads with purpose=truck_photo (max 10). |
Sending only one changed day in openingHours | openingHours is a full weekly replacement, not a merge. Send every day you want retained. Day numbering is 0=Sunday ... 6=Saturday. |
Calling only PATCH .../location from new mobile code | Prefer PUT /api/v1/owner/trucks/:id/location. PATCH remains a compatibility alias, and both return the updated owner truck. |
| Probing other owners' trucks via error codes | You cannot — errors are 404-before-403. Non-existent → 404 NOT_FOUND; exists-but-not-yours → 403 FORBIDDEN. |
| Assuming the public truck schema matches the owner schema | The owner response exposes featuredUntil, contactPhone, whatsappNumber, ordersCount that the public truck-detail view hides. Do not reuse the public model. |
| Generating a share link before setting a location | POST .../location/share-link returns 409 with no lat/lng. Set a location (create with coords, PATCH .../location, or open the truck) first. The token is reused, not regenerated. |
| Hardcoding English-only copy | English lives at the top level (required at create). Arabic is additive and optional via translations.ar.{name,description,address}. Send Accept-Language: ar for Arabic error/notification text. |
Related
- Payments — how the Paymob webhook settles the pending order from
/featureand flipsisFeatured. - Reviews — the customer-facing review lifecycle behind the owner triage feed.
- Uploads — the
POST /api/v1/uploadsingest used fortruck_photo. - API reference — full endpoint and schema reference.