Surplus

End-of-route "surplus" listings: a driver publishes leftover water at a fixed price, and a customer reserves the whole lot β€” which auto-creates an order. Paths are relative to the /api/v1 prefix; all routes require Authorization: Bearer {token}.

See Common errors. A reservation creates an order, so Orders and the order lifecycle apply from there on.

Endpoints

Method URI Role Description
POST /surplus DRIVER Publish a surplus listing
GET /surplus/me DRIVER My active listings
DELETE /surplus/{surplusId} DRIVER Cancel a listing
POST /surplus/{surplusId}/cancel DRIVER Cancel a listing (alias of DELETE)
GET /surplus/nearby any Nearby active listings
GET /surplus any Nearby active listings (alias of /surplus/nearby)
POST /surplus/{surplusId}/reserve CLIENT Reserve a listing (creates an order)

A listing may not promise more liters than the driver has free: the tank they declared when going online, minus the liters committed to their active orders and to their other live listings. Money fields end in _usd (decimal), derived from integer _cents.


POST /surplus

Publishes a surplus listing. The driver enters totalAmount β€” the total gross they want to receive for the whole listing. The listing expires after durationMinutes (default 6 h if omitted).

Request body

Field Type Required Rules
availableLiters integer yes 500–50000
totalAmount number yes > 0, ≀ 100000 β€” total gross the driver wants to receive
description string no ≀ 280 chars
latitude number yes between βˆ’90 and 90
longitude number yes between βˆ’180 and 180
address string yes 3–280 chars
durationMinutes integer no 15–720 (max 12 h); defaults to 360 (6 h)

Response 201

{
  "listing": {
    "id": 5,
    "driver_id": 3,
    "city_id": 1,
    "available_liters": 5000,
    "price_per_liter_cents": 2,
    "total_price_cents": 10000,
    "price_per_liter_usd": 0.02,
    "total_price_usd": 100.0,
    "description": "Excedente fin de ruta",
    "latitude": 10.487,
    "longitude": -66.88,
    "address": "Av. Principal, Las Mercedes",
    "status": "ACTIVA",
    "sold_liters": 0,
    "remaining_liters": 5000,
    "expires_at": "2026-06-26T14:00:00+00:00",
    "created_at": "2026-06-26T13:00:00+00:00"
  }
}

Each listing carries a status: ACTIVA, RESERVADA (reserved β†’ order created), EXPIRADA (past expires_at), or CANCELADA.

Errors

Status Body When
409 { "error": "InsufficientLiters", "message": "…", "remaining_liters": 1000, "requested_liters": 5000 } availableLiters exceeds the driver's free liters: their declared capacity β€” or the vehicle's, when nothing is declared β€” minus what active orders and other live listings already promise. Only a driver with no vehicle on file and nothing declared is unchecked

GET /surplus/me

The caller's currently active listings (not expired, not cancelled, with liters left).

Response 200 β€” { "listings": [ { … } ] } (each entry is a listing, same shape as POST /surplus).


DELETE /surplus/{surplusId}

Cancels a listing (sets its status to CANCELADA). Only the listing's owner may cancel, and only while the listing is ACTIVA. POST /surplus/{surplusId}/cancel is an exact alias.

Response 200 β€” { "ok": true }.

Errors

Status Body When
409 { "error": "Conflict", "message": "No es tu listing." } The caller does not own the listing
409 { "error": "Conflict", "message": "El remate ya no estΓ‘ disponible." } The listing's status is not ACTIVA (RESERVADA, EXPIRADA or CANCELADA)

POST /surplus/{surplusId}/cancel

Alias of DELETE /surplus/{surplusId} β€” identical behavior, response, and errors.


GET /surplus/nearby

Active listings within a radius of a point, enriched with client-facing pricing (base_price_* and client_pays_*) and the publishing driver's equipment (has_motopump, hose_length_meters). GET /surplus is an exact alias.

Pricing is previewed for paymentMethod (defaults to CASH_USD).

Query

Field Type Required Rules
lat number yes between βˆ’90 and 90
lng number yes between βˆ’180 and 180
radiusKm number no > 0, ≀ 100; defaults to the platform's configured surplus radius (see Admin config)
paymentMethod string no an active integration code or PAYMENT_FORM; defaults to CASH_USD
paymentFormId integer conditional required when paymentMethod=PAYMENT_FORM; must be an active payment form

Response 200

{
  "listings": [
    {
      "id": 5,
      "driver_id": 3,
      "available_liters": 5000,
      "remaining_liters": 5000,
      "total_price_cents": 10000,
      "total_price_usd": 100.0,
      "price_per_liter_usd": 0.02,
      "base_price_cents": 12195,
      "base_price_usd": 121.95,
      "client_pays_cents": 12195,
      "client_pays_usd": 121.95,
      "has_motopump": true,
      "hose_length_meters": 30,
      "address": "Av. Principal, Las Mercedes",
      "latitude": 10.487,
      "longitude": -66.88,
      "expires_at": "2026-06-26T14:00:00+00:00",
      "distance_km": 4.45,
      "eta_minutes": 32,
      "driver_busy": true,
      "eta_provisional": false,
      "queue_ahead": 1
    }
  ],
  "blocked_reason": null,
  "active_order_id": null
}
Field Type Description
blocked_reason string | null "ActiveOrderExists" when the caller is a client with an order in flight; null otherwise
active_order_id integer | null That order's id, or null

listings is empty whenever blocked_reason is set. A caller with no client orders in flight β€” a driver browsing, for instance β€” is never blocked.

Equipment fields

Field Type Notes
has_motopump boolean | null null when the driver has no vehicle on file
hose_length_meters integer | null null when the driver has no vehicle on file, or when their vehicle has no hose length recorded

Distance and ETA fields

Measured from the publishing driver's current position to the queried lat/lng, not from the listing's own latitude/longitude.

Field Type Notes
distance_km number | null Straight-line distance; null when the driver has no known location
eta_minutes number | null Estimated minutes until the driver reaches lat/lng; null when the driver has no known location
driver_busy boolean The driver has deliveries to serve before this one
eta_provisional boolean eta_minutes can still change
queue_ahead integer Number of deliveries the driver serves first

GET /surplus

Alias of GET /surplus/nearby β€” identical query and response.


POST /surplus/{surplusId}/reserve

A customer reserves the whole listing. This creates an order (CONFIRMED for cash, WAITING_FOR_PAYMENT for online methods) and returns it in the CLIENT-sanitized shape (see Orders β†’ the order object).

Request body

Field Type Required Rules
latitude number yes between βˆ’90 and 90
longitude number yes between βˆ’180 and 180
address string yes 3–280 chars
addressReference string | null no max 255 chars
paymentMethod string no an active integration code other than KRECE, or PAYMENT_FORM; defaults to CASH_USD
paymentFormId integer conditional required when paymentMethod=PAYMENT_FORM; must be an active payment form

Response 200 β€” { "order": { … } } (CLIENT view). The order includes surplus_listing_id (the listing it came from); a non-null value marks the order as a surplus reservation. Normal orders have surplus_listing_id: null.

The order also carries the distance/ETA fields described in Orders β†’ the order object.

The order also carries promo_credit_* and client_charged_*. A surplus reservation can only draw on the client's SURPLUS and ANY credit buckets (see Credit); with none available, promo_credit_* is 0 and client_charged_* equals client_pays_*.

Errors

Status Body When
409 { "error": "Conflict", "message": "El remate ya no estΓ‘ disponible." } The listing was sold, cancelled, or expired
409 { "error": "ActiveOrderExists", "message": "…", "active_order_id": 42 } The client already has an order in flight (BROADCASTING … ARRIVED)
422 { "error": "ExchangeRateUnavailable", "message": "…" } There is no active BCV (VES) rate to snapshot on the order
422 { "message": "…" } Method not available, or missing/invalid paymentFormId

Examples

# Driver: publish surplus
curl -X POST /api/v1/surplus \
  -H "Authorization: Bearer {driver_token}" \
  -H "Content-Type: application/json" \
  -d '{"availableLiters": 5000, "totalAmount": 100, "latitude": 10.487, "longitude": -66.88, "address": "Av. Principal", "durationMinutes": 60}'

# Client: reserve a listing (cash)
curl -X POST /api/v1/surplus/5/reserve \
  -H "Authorization: Bearer {client_token}" \
  -H "Content-Type: application/json" \
  -d '{"latitude": 10.49, "longitude": -66.85, "address": "Calle 2, Casa 4"}'