Marketplace — Listings & Ads
How a listing goes live the instant you create it, how the optional paid publish/renew flow works, and how an advertisement stays pending until you pay AND an admin approves it.
The Marketplace domain is two very different objects with opposite "create" semantics, plus a shared paid-services layer. Get this distinction right before you build anything:
- A MarketplaceListing goes live the moment you create it (
status: "active", searchable, no expiry). Payment is optional promotion, not a visibility gate. - An Advertisement is created as a pending draft that serves nothing. Two independent things have to happen before it is actually served: a captured payment (which flips it to
activefor the purchased window) and an admin approval (which flips it toapproved). They write the samestatuscolumn, so the order they land in matters — see the Advertisement states table.
Everything sits under /api/v1, across three mounted route trees:
| Tree | Prefix | What it does |
|---|---|---|
| Marketplace | /api/v1/marketplace/* + /api/v1/owner/marketplace/* | Public discovery + seller contact + owner listing CRUD + paid publish/renew |
| Distribution | /api/v1/marketplace-distribution/* | The generic paid-services surface (pricing/quote/payment-order/cancel/activations) for the marketplace_listing service that publish/renew delegate into |
| Advertising | /api/v1/marketplace-advertising/* | Drafting + paid-running of ads that promote a truck or a listing |
Auth & headers. Discovery (GET /marketplace/listings, GET .../:id) and the two pricing endpoints are anonymous-allowed. Send an optional Bearer token on listing discovery/detail to receive the caller-specific isFavorite; guests receive false. Contact, favorites, owner CRUD, every quote/order/activation call, and ad drafting require Authorization: Bearer <oat_...>.
Response envelope is always one of:
{
"data": {
/* payload */
},
"meta": { "requestId": "req_01..." }
}{ "error": { "code": "CONFLICT", "message": "..." }, "meta": { "requestId": "req_01..." } }A freshly created listing is already live.
POST /api/v1/owner/marketplace/listings returns status: "active", sets publishedAt = now, leaves expiresAt = null, and indexes the listing for search immediately. There is no draft gate.
Because of this, calling POST .../:id/publish on a new listing returns 409 CONFLICT "Listing is already published". Treat publish as an optional re-publication / promotion step for a listing that is not active (expired/archived/draft), not the required first step.
Advertisements are the mirror image — POST /api/v1/marketplace-advertising/ads lands status: "pending" and serves nothing until it is paid (→ active) and admin-approved (→ approved). Build the two flows differently.
The flow at a glance
Listing happy path (create = live; payment optional)
Step 1 — Upload photos
Upload each image via POST /api/v1/uploads and collect the returned fileIds. See Uploads.
Step 2 — Create the listing → it is live
POST /api/v1/owner/marketplace/listings with the listing fields + fileIds. Response is 201 with status: "active". The listing is now visible in discovery and searchable. No payment required.
Step 3 — Buyers discover it
Anyone can GET /api/v1/marketplace/listings (filtered discovery) and GET /api/v1/marketplace/listings/:id (detail; increments viewsCount). Authenticated callers also receive the correct isFavorite flag.
Step 3b — Save across devices (authenticated)
Use POST / DELETE /api/v1/marketplace/listings/:id/favorite to set the saved state idempotently. Hydrate the saved-list screen from GET /api/v1/me/favorite-listings.
Step 4 — A buyer contacts the seller
A signed-in buyer POSTs /api/v1/marketplace/listings/:id/contact to get the seller's contact channels + a marketplace conversation id, then chats via the Chat & Realtime domain.
Step 5 — (Optional) Buy a paid publication term
To promote: GET /api/v1/marketplace-distribution/pricing → POST .../quote → POST .../payment-orders, open the Paymob sheet with clientSecret, then poll GET .../payment-orders/:id until paid. The activation sets/refreshes publishedAt + expiresAt. Extend later with the renew endpoint.
Advertisement happy path (draft → pay → await approval)
Step 1 — Draft the ad → it is PENDING (serves nothing)
POST /api/v1/marketplace-advertising/ads referencing exactly one of foodTruckId / listingId that you own. Response is 201 with status: "pending".
Step 2 — Quote + pay for a run
POST /api/v1/marketplace-advertising/quote then POST /api/v1/marketplace-advertising/payment-orders with the ad id as targetId. Open the Paymob sheet with clientSecret.
Step 3 — Captured payment flips it to active
On a captured payment the ad becomes status: "active" with a startDate/endDate window taken from the activation. (Zero-price path activates immediately, clientSecret: null.)
Step 4 — Admin approval gates serving
An admin must approve the ad (admin surface, outside these docs) before it is served. Approval sets status: "approved" — and the admin can approve while the ad is still pending (unpaid). Because payment and approval write the same status column, the last one to land wins the visible value: pay-then-approve ends approved, approve-then-pay ends active. Rejection (status: "rejected") refunds any paid run. The run expires automatically at endDate (status: "expired").
Listing endpoints in detail
GET /api/v1/marketplace/listings — discover (anonymous)
Returns only status: "active" listings whose expiresAt is null or in the future, ordered by publishedAt desc.
Filters (all optional, combinable):
| Param | Meaning |
|---|---|
listingType | sale | rent | custom |
city | exact city match |
truckType (alias category) | case-insensitive partial match on the free-text truckType column; comma-separated = ANY-of |
minPrice / maxPrice | inclusive range, minor units |
search (alias q) | case-insensitive partial match on title + description |
limit | default 20, max 50 |
422 VALIDATION_ERROR on a malformed query.
GET /api/v1/marketplace/listings?listingType=sale&city=Riyadh&maxPrice=7000000&q=trailer&limit=20 HTTP/1.1
Accept-Language: en{
"data": {
"items": [
{
"id": "lst_01jq8zq1a3c5e7g9j1l3n5p7q9",
"ownerId": "usr_01...",
"truckId": null,
"listingType": "sale",
"title": "2020 Mobile Food Cart — Fully Equipped",
"priceMinor": 6500000,
"currencyCode": "SAR",
"city": "Riyadh",
"truckType": "trailer",
"viewsCount": 42,
"isFavorite": true,
"contactPreferences": ["whatsapp", "phone"],
"publishedAt": "2026-06-10T08:00:00.000Z",
"expiresAt": null,
"createdAt": "2026-06-10T08:00:00.000Z",
"images": [{ "thumb": "https://...", "medium": "https://...", "original": "https://..." }]
}
]
},
"meta": { "requestId": "req_01..." }
}GET /api/v1/marketplace/listings/:id — detail (anonymous-allowed)
Resolves only an active, non-expired, non-deleted listing — otherwise 404 NOT_FOUND. Side effect: atomically increments viewsCount on every fetch. Response is { listing: { ...fields, isFavorite, images: [...] } }; isFavorite=false for guests.
Favorite listings — authenticated, idempotent
POST /api/v1/marketplace/listings/lst_01jq.../favorite HTTP/1.1
Authorization: Bearer oat_abc123{ "data": { "isFavorite": true }, "meta": { "requestId": "req_01..." } }Favoriting an already-saved listing is still 200; unknown or non-visible listing ids return 404.
DELETE /api/v1/marketplace/listings/lst_01jq.../favorite HTTP/1.1
Authorization: Bearer oat_abc123{ "data": { "isFavorite": false }, "meta": { "requestId": "req_01..." } }Deleting a missing favorite remains 200.
GET /api/v1/me/favorite-listings returns a bare array in data, newest-favorited first. Every element has the same public listing shape, full image FileRefs, and isFavorite=true. Listings that are deleted, inactive, or expired are omitted.
POST /api/v1/marketplace/listings/:id/contact — contact the seller (Bearer)
Find-or-creates a marketplace conversation and returns the seller's contact channels. The listing must be active (else 404). 409 CONFLICT if you contact your own listing.
POST /api/v1/marketplace/listings/lst_01jq8zq1a3c5e7g9j1l3n5p7q9/contact HTTP/1.1
Authorization: Bearer oat_abc123{
"data": {
"conversationId": "con_01...",
"contactPreferences": ["whatsapp", "phone"],
"owner": {
"id": "usr_01...",
"businessName": "Crispy Cart Co.",
"phone": "+966555012345",
"email": "[email protected]"
}
},
"meta": { "requestId": "req_01..." }
}contactPreferences is the array that drives which channels you surface in the contact
bottom-sheet — phone, whatsapp, and/or chat. The owner.phone / owner.email come from the
owner's business profile, falling back to the user's own phone/email. Use the conversationId to
start chatting via the Chat & Realtime domain.
GET /api/v1/owner/marketplace/listings — your own listings (Bearer)
All non-soft-deleted listings you own, across every status (draft, pending_payment, active, expired, suspended, archived), newest first. The owner serializer adds status, paidActivationId, and updatedAt — fields the public serializer omits.
POST /api/v1/owner/marketplace/listings — create (goes live) (Bearer)
Any authenticated user can create — there is no owner-capability gate. Returns 201 with the created listing at status: "active".
Body fields:
| Field | Rules |
|---|---|
listingType | required — sale | rent | custom |
title | required, 2–200 chars |
description | ≤ 5000 chars |
priceMinor | integer ≥ 0 (minor units) |
currencyCode | 3 chars, defaults SAR when omitted |
billingPeriod, city, region, truckType, condition, size | optional strings |
lat / lng | optional decimals |
modelYear | 1900–2100 |
equipment | string array, ≤ 50 items |
contactPreferences | array of phone | whatsapp | chat, ≤ 3 |
truckId | optional; locked once the listing is live (See Implementation notes) |
fileIds | ≤ 8 image fileIds — array order = display order |
POST /api/v1/owner/marketplace/listings HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json
{
"listingType": "sale",
"title": "2020 Mobile Food Cart — Fully Equipped",
"description": "Custom 4m trailer with double griddle, fryer, drinks cooler, generator.",
"priceMinor": 6500000,
"currencyCode": "SAR",
"city": "Riyadh",
"truckType": "trailer",
"modelYear": 2020,
"equipment": ["double griddle", "deep fryer", "generator"],
"contactPreferences": ["whatsapp", "phone"],
"fileIds": ["fil_01jq8zp1a3c5e7g9j1l3n5p7q9"]
}{
"data": {
"listing": {
"id": "lst_01jq8zq1a3c5e7g9j1l3n5p7q9",
"status": "active",
"listingType": "sale",
"title": "2020 Mobile Food Cart — Fully Equipped",
"priceMinor": 6500000,
"currencyCode": "SAR",
"paidActivationId": null,
"publishedAt": "2026-06-21T10:00:00.000Z",
"expiresAt": null,
"createdAt": "2026-06-21T10:00:00.000Z",
"updatedAt": "2026-06-21T10:00:00.000Z",
"images": [{ "thumb": "https://...", "medium": "https://...", "original": "https://..." }]
}
},
"meta": { "requestId": "req_01..." }
}PATCH /api/v1/owner/marketplace/listings/:id — update (Bearer, must own)
Partial update of the same fields. 403 FORBIDDEN if not yours, 404 if missing.
fileIds on PATCH is a FULL REPLACEMENT set, not an append. Omit it to keep images unchanged; supply it to replace — anything not in the array is detached. Array order is display order. Sending a single new id replaces all images with that one.
truckId is immutable once live. Changing truckId on a listing that is active or has ever been published (publishedAt != null) returns 409 CONFLICT. Set truckId at create time.
DELETE /api/v1/owner/marketplace/listings/:id — soft-delete (Bearer, must own)
Sets status: "soft_deleted" + deletedAt, removes the listing from search, and detaches all images. Returns { "success": true }. 403/404 as above.
POST /api/v1/owner/marketplace/listings/:id/publish — optional paid promotion (Bearer, must own)
Delegates into the distribution module to create a payment order for serviceType: marketplace_listing.
Body: durationDays (1–365, required), currencyCode (optional — defaults to the listing's currency / SAR).
publish returns 409 CONFLICT "Listing is already published" when the listing is active —
and listings are auto-active on create, so calling publish right after create always
conflicts. It also 409s on suspended / soft_deleted. publish is effectively usable only on
an expired / archived / draft listing.
POST /api/v1/owner/marketplace/listings/lst_01.../publish HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json
{ "durationDays": 30, "currencyCode": "SAR" }{
"data": {
"paymentOrder": {
"id": "pay_01...",
"orderNumber": "MP-2026-000123",
"status": "pending",
"totalAmountMinor": 9000,
"currencyCode": "SAR",
"gateway": "paymob",
"gatewayReference": "..."
},
"clientSecret": "csk_...",
"immediatelyActivated": false
},
"meta": { "requestId": "req_01..." }
}POST /api/v1/owner/marketplace/listings/:id/renew — extend a paid term (Bearer, must own)
Same body/response as publish. 409 CONFLICT if the listing has never been published (publishedAt == null), or if it is suspended / soft_deleted. On payment the activation extends the term and re-applies the listing handler.
publish vs renew preconditions differ — surface distinct messages. publish 409s on
active/suspended/soft_deleted. renew 409s when publishedAt is null (never published) and
on suspended/soft_deleted. After the order is created, both feed into the same distribution
payment flow below.
The paid distribution flow (/api/v1/marketplace-distribution/*)
This is the generic paid-services surface for marketplace_listing. The owner publish/renew endpoints above create the payment order for you; you can also drive these endpoints directly to quote and settle.
GET /api/v1/marketplace-distribution/pricing — pricing rows (anonymous)
Returns dailyPriceMinor + minDurationDays/maxDurationDays per currency. Use it to compute cost client-side before quoting.
{
"data": {
"items": [
{
"id": "psp_01...",
"serviceType": "marketplace_listing",
"currencyCode": "SAR",
"dailyPriceMinor": 300,
"minDurationDays": 1,
"maxDurationDays": 90,
"effectiveFrom": "2026-01-01T00:00:00.000Z"
}
]
},
"meta": { "requestId": "req_01..." }
}POST /api/v1/marketplace-distribution/quote — quote a publication (Bearer)
Body: targetId (the listing id), durationDays (1–365), currencyCode (3 chars, required here).
POST /api/v1/marketplace-distribution/quote HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json
{ "targetId": "lst_01jq8zq1a3c5e7g9j1l3n5p7q9", "durationDays": 30, "currencyCode": "SAR" }{
"data": {
"quote": {
"serviceType": "marketplace_listing",
"targetType": "marketplace_listing",
"targetId": "lst_01jq8zq1a3c5e7g9j1l3n5p7q9",
"durationDays": 30,
"unitPriceMinor": 300,
"totalAmountMinor": 9000,
"currencyCode": "SAR",
"requiresPayment": true,
"expiresAt": "2026-06-21T10:15:00.000Z"
}
},
"meta": { "requestId": "req_01..." }
}POST /api/v1/marketplace-distribution/payment-orders — create the order (Bearer)
Same body as quote. Returns 201 with paymentOrder, clientSecret, immediatelyActivated, and activation.
Zero-price path. If the computed price resolves to zero, the response has
immediatelyActivated: true, clientSecret: null, and the listing is activated synchronously
— skip the payment sheet entirely. When clientSecret is non-null, hand it to the Paymob SDK;
the gateway webhook is the source of truth for settlement. Do not assume paid from the sheet
result — re-fetch the order (below) after the sheet closes.
{
"data": {
"paymentOrder": {
"id": "pay_01...",
"status": "pending",
"totalAmountMinor": 9000,
"currencyCode": "SAR",
"gateway": "paymob"
},
"clientSecret": "csk_...",
"immediatelyActivated": false,
"activation": null
},
"meta": { "requestId": "req_01..." }
}GET /api/v1/marketplace-distribution/payment-orders/:id — order status (Bearer)
Poll this after the payment sheet closes to learn pending → paid. 403 if you are not the payer; 404 if it is not a marketplace_listing order (the per-feature URL never exposes other features' orders).
POST /api/v1/marketplace-distribution/payment-orders/:id/cancel — cancel (Bearer)
Only pending orders cancel; 409 CONFLICT otherwise. 403 if not the payer.
GET /api/v1/marketplace-distribution/activations — your activations (Bearer)
Each row is { id, startsAt, expiresAt, status (active|expired|cancelled), renewedFromId }. renewedFromId chains renewals so you can render a term history.
The advertising flow (/api/v1/marketplace-advertising/*)
Same paid-services shape as distribution, plus a unique draft step (POST .../ads). Remember: an ad serves nothing until paid AND admin-approved.
POST /api/v1/marketplace-advertising/ads — draft a pending ad (Bearer)
Body: title (required), type (promotion | offer | announcement | boost), placement (optional, ≤ 24 chars), and exactly one of foodTruckId / listingId.
409 CONFLICTif neither reference is supplied, or if you reference a truck/listing you do not own.404 NOT_FOUNDif the referenced truck/listing does not exist.
Returns 201 with status: "pending". (The draft response carries id, title, type, placement, status, foodTruckId, listingId, createdAt — the startDate/endDate window only exists after a paid run activates it.)
POST /api/v1/marketplace-advertising/ads HTTP/1.1
Authorization: Bearer oat_abc123
Content-Type: application/json
{
"title": "Weekend 2-for-1 shawarma",
"type": "promotion",
"placement": "homepage",
"foodTruckId": "trk_01jq8z4b2k6h7n8m9p0r3s5t7v"
}{
"data": {
"advertisement": {
"id": "adv_01jq8zk1a3c5e7g9j1l3n5p7q9",
"title": "Weekend 2-for-1 shawarma",
"type": "promotion",
"placement": "homepage",
"status": "pending",
"foodTruckId": "trk_01jq8z4b2k6h7n8m9p0r3s5t7v",
"listingId": null,
"createdAt": "2026-06-21T10:00:00.000Z"
}
},
"meta": { "requestId": "req_01..." }
}POST /api/v1/marketplace-advertising/quote — quote a run (Bearer)
Body: targetId (the advertisement id), durationDays (1–365), currencyCode (3 chars, required). Returns the same { quote } shape as the distribution quote.
POST /api/v1/marketplace-advertising/payment-orders — pay for a run (Bearer)
Same body as quote. Returns 201 with paymentOrder, clientSecret, immediatelyActivated, activation. On captured payment the ad handler flips the ad to status: "active" and sets startDate/endDate from the activation window. Zero-price path activates immediately (clientSecret: null). The same webhook-is-truth rule applies — re-fetch the order after the sheet closes.
GET /api/v1/marketplace-advertising/payment-orders/:id — order status (Bearer)
403 if not the payer; 404 if it is not an advertisement order.
POST /api/v1/marketplace-advertising/payment-orders/:id/cancel — cancel (Bearer)
Only pending orders; 409 otherwise. 403 if not the payer.
GET /api/v1/marketplace-advertising/pricing — pricing rows (anonymous)
dailyPriceMinor + minDurationDays/maxDurationDays per currency (same shape as distribution pricing).
GET /api/v1/marketplace-advertising/activations — your ad activations (Bearer)
{ startsAt, expiresAt, status, renewedFromId } per run.
Lifecycles
Listing states
| State | Meaning | How you got here | What's allowed next |
|---|---|---|---|
active | Live + searchable | Create (the default), or publish/renew paid then captured | Edit, soft-delete, renew; publish will 409 |
expired | Paid term lapsed | Scheduler ran the activation natural undo | publish (re-publish), renew |
suspended | Admin-hidden from discovery; owner can still see/edit | Admin suspend (admin scope) | Admin restore; publish/renew 409 |
archived | Paid activation refunded | Refund → undo with archive | publish, renew |
soft_deleted | Hidden everywhere | Owner DELETE, or admin takedown | Admin restore only |
draft | Enum value exists; not produced by the normal create path | n/a in the current flow | publish |
pending_payment | Legacy paid-gate enum value; not used by current auto-publish create | n/a in the current flow | n/a |
The listing enum is draft | pending_payment | active | expired | suspended | archived | soft_deleted. Use active for live listings and soft_deleted with an underscore for deleted
listings.
Listing transitions
- (none) →
active—POST /api/v1/owner/marketplace/listings(owner; auto-publish on create). expired/archived/draft→active—POST .../:id/publishthen pay (activation handler setsactive+publishedAt/expiresAt).active/expired→active(extended term) —POST .../:id/renewthen pay.active→expired— system scheduler, on paid-term natural expiry.active→archived— system, on payment refund (undo with archive).- any →
soft_deleted—DELETE /api/v1/owner/marketplace/listings/:id(owner). active→suspended/suspended/soft_deleted→ prior — admin suspend/restore (admin dashboard/API; see Admin and API reference).
Advertisement states
The status column is written by two independent actors — the payment activation handler (pending/approved → active on capture) and admin moderation (pending/rejected → approved, anything → rejected). An ad only actually serves once it has both a live paid run and an approval, so do not read a single status value as "is it serving".
| State | Meaning | How you got here | What's allowed next |
|---|---|---|---|
pending | Drafted, not served | POST .../ads | Quote + pay a run; admin approve/reject |
approved | Admin approved; serves only if a paid run is also live | Admin approve (admin scope) — can fire while still pending/unpaid | Pay a run → active; admin may reject |
active | Paid run captured; serves between startDate and endDate if also admin-approved | Captured payment → ad handler apply | Runs until endDate; admin may approve/reject |
rejected | Admin reject, or paid run refunded | Admin reject (refunds a live paid run), or refund undo | Admin may re-approve |
expired | Run window ended | System undo on run-window end (archive=false) | Draft + pay a new run |
Advertisement transitions
- (none) →
pending—POST /api/v1/marketplace-advertising/ads(owner). pending/approved→active—POST .../payment-ordersthen captured payment → ad handler apply.pending/rejected→approved— admin approve (admin dashboard/API; see Admin and API reference). Can fire while the ad is still unpaid.- any →
rejected— admin reject (refunds a live paid run; admin dashboard/API). active→expired— system, on run-window end.
Payment and admin approval write the same status column independently — there is no combined
"live" status. After both happen, the field shows whichever landed last (active or approved).
Treat "is this ad serving?" as "approved AND has a live paid run within startDate/endDate",
not as a single status check.
Implementation Notes
| Integration issue | Correct handling |
|---|---|
| Treating a newly created listing as a hidden draft | It is status: "active" and live the instant POST .../listings returns. No payment needed for visibility. Render it immediately. |
Calling publish right after create | It 409s with "Listing is already published" because the listing is already active. Only call publish on a non-active (expired/archived/draft) listing. |
Showing the same error for publish and renew failures | They differ: publish 409s on active/suspended/soft_deleted; renew 409s when never-published (publishedAt null) and on suspended/soft_deleted. Surface a distinct message for each. |
| Building "ad create = live" | An ad lands pending and serves nothing. It needs a captured payment (→ active) and an admin approval. Build draft → pay → await-approval. |
| Sending both / neither truck & listing on an ad | An ad references exactly one of foodTruckId / listingId, and you must own it — else 409 CONFLICT (neither/not-owned) or 404 (missing). |
Assuming a paid result from the payment sheet | The gateway webhook is the source of truth. After the sheet closes, re-fetch GET .../payment-orders/:id for the real pending → paid. |
| Forgetting the zero-price shortcut | When the price is zero the order response has immediatelyActivated: true and clientSecret: null — skip the payment sheet; it is already activated. |
Trying to change truckId after a listing went live | truckId is locked once active/ever-published — PATCH 409s. Set it at create time. |
Sending one new fileId on PATCH expecting an append | fileIds on PATCH is a full replacement set — omit to keep images, supply the complete desired array (order = display order). |
| Expecting the public list to include drafts/expired | Discovery returns only active, non-expired, non-deleted listings. Use GET /owner/marketplace/listings for every status (it adds status + paidActivationId). |
Omitting currencyCode on a quote/order | The distribution & advertising quote/payment-orders validators require a 3-char currencyCode. (Only the owner publish/renew body treats it as optional, defaulting to the listing's currency / SAR.) |
| Contacting your own listing | 409 CONFLICT. A non-active/expired/deleted listing returns 404 (not 403) on detail and contact. |
| Reading the wrong status label | Trust the model enum: active and soft_deleted are the real values. |
Related
- Payments — the Paymob payment-order + webhook settlement model the paid flows feed into.
- Chat & Realtime — the conversation the contact endpoint returns a
conversationIdfor. - Uploads — mint the
fileIds you attach to a listing. - Truck Management — the truck an ad (or a listing's
truckId) can reference. - API reference — full endpoint and schema catalogue.
Jobs — Post, Publish, Hire
How truck owners post staffing listings that go live instantly, optionally promote them with a paid term, and hire — and how job-seekers discover, apply to, and track jobs.
Chat & Realtime (SSE)
How to integrate 1:1 and group chat — durable REST endpoints plus the two realtime transports (Socket.IO and SSE) that deliver live messages, read receipts, and typing indicators.