Skip to main content
Docs menu
POST

/addons/route-optimization/jobs

Submit an asynchronous route optimization job

Path

POST/api/v1/partners/addons/route-optimization/jobs
Authentication requiredapi-key

curl example

curl -X POST "https://api.route4green.com/api/v1/partners/addons/route-optimization/jobs" \
  -H "api-key: YOUR_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "content-type: application/json" \
  -d '{
  "external_reference": "string",
  "replaces_job_id": "string",
  "optimization_options": {
    "delivery_mode": {},
    "kind_of_plan": {},
    "tour_mode": "string",
    "backhaul_order": {},
    "vehicle_trips": {},
    "engine": {},
    "core_transport_mode": "string"
  },
  "vehicles": [
    {
      "external_vehicle_id": "string",
      "resource_id": 0,
      "from_address": "string",
      "from_lat": 0,
      "from_lon": 0,
      "from_working_time": "2026-01-01T00:00:00+07:00",
      "to_working_time": "2026-01-01T00:00:00+07:00",
      "handling_unit_ids": [
        0
      ],
      "height_of_vehicle": 0,
      "length_of_vehicle": 0,
      "width_of_vehicle": 0,
      "vehicle_tonnage": 0,
      "has_permit": false,
      "to_address": "string",
      "to_lat": 0,
      "to_lon": 0
    }
  ],
  "orders": [
    {
      "external_order_id": "string",
      "external_reference": "string",
      "transport_mode": {},
      "depot_ref": "string",
      "handling_unit_id": 0,
      "service_id": 0,
      "resource_id": 0,
      "distance": 0,
      "pickup_address": "string",
      "pickup_lat": 0,
      "pickup_lon": 0,
      "pickup_wid": 0,
      "pickup_date_time": "2026-01-01T00:00:00+07:00",
      "pickup_date_time_to": "2026-01-01T00:00:00+07:00",
      "drop_address": "string",
      "drop_lat": 0,
      "drop_lon": 0,
      "drop_wid": 0,
      "drop_date_time": "2026-01-01T00:00:00+07:00",
      "drop_date_time_to": "2026-01-01T00:00:00+07:00",
      "loading_time": 0,
      "unloading_time": 0,
      "max_vehicle_weight": 0,
      "forbidden_time_windows": [
        "string"
      ],
      "rlength": 0,
      "rwidth": 0,
      "rheight": 0,
      "rweight": 0,
      "count_of_parcels": 0,
      "sender_name": "string",
      "sender_phone": "string",
      "receiver_name": "string",
      "receiver_phone": "string"
    }
  ],
  "depots": [
    {
      "depot_ref": "string",
      "address": "string",
      "lat": 0,
      "lon": 0
    }
  ],
  "baseline": {
    "km_type": {},
    "includes_return_to_depot": false,
    "routes": [
      {}
    ],
    "km_basis": {},
    "sequence_known": false
  }
}'

Parameters

NameInTypeRequiredDescription
Idempotency-KeyheaderstringYesClient-scoped key retained indefinitely; maximum 128 chars

Request body

FieldTypeRequiredDescription
external_referencestringNoClient-supplied identifier for this job, echoed back on every read
replaces_job_idstring (uuid)NoJob ID this submission replaces. The referenced job is cancelled immediately, inside the same transaction that creates this new job; it can never be kept as a fallback. Only a job that is still QUEUED and has not yet been claimed by the optimization queue is accepted; a job that has already started processing fails the request with 409 JOB_ALREADY_PROCESSING.
optimization_optionsobjectYesOptimization mode and delivery/planning settings
vehiclesobject[]YesVehicles available for this job
ordersobject[]YesOrders to assign and sequence across the given vehicles
depotsobject[]NoDepots the orders may start from (lastmile) or end at (firstmile), referenced by orders[].depot_ref. Vehicles keep their own start points.
baselineobjectNoThe partner's own plan for the same day (plan versus plan). Optional for every key, measurement keys included. When present, GET /jobs/:id/result carries baseline_comparison; without it baseline_comparison is null. A baseline can also be attached later with PUT /jobs/:id/baseline.

Fields of optimization_options

FieldTypeRequiredDescription
delivery_mode1 | 2 | 3 | 4YesDelivery mode. 1: normal, 2: same day delivery, 3: express 2H delivery, 4: 4H delivery
kind_of_plan1 | 2YesPlanning mode. 1: actual planning, 2: plan in advance
tour_modestringYesOptimization mode: 6 parameters separated by semicolons. Position 1: minimize total distance, 2: minimize vehicle count, 3: balance workload across vehicles, 4: prioritize time windows, 5: require an available driver, 6: time-limited route as an integer count of minutes (not a flag). Positions 1-5 are 0/1 flags.
backhaul_ordermixed | deliveries_firstNoStop order on trips that both deliver and collect (pickupdrop jobs). 'mixed' (default): each collection where it is shortest, between deliveries if shorter. 'deliveries_first': every delivery of the trip first, then the collections; a trip keeps the mixed order when that would break a time window. Each route of the result reports the order it got in stop_order.
vehicle_tripsmultiple | single | balancedNoHow many trips a vehicle may run, on jobs planned by engine 'vroom' (pickupdrop, first-mile, and last-mile with window priority); other jobs ignore it. 'multiple' (default): a vehicle may come back to its depot and load again, so the work can sit on fewer vehicles. 'single': one trip per vehicle, deliveries loaded at the start and collections unloaded at the end, so idle vehicles take the work instead of reloads; orders that do not fit are unassigned with their reason. 'balanced': like 'single', with the load spread close to evenly across the vehicles, so no vehicle carries a near-empty trip; if that leaves an order out, the plan falls back to 'single'.
enginecoreNoForce the planning engine. 'core': the job is planned by the optimization core even where Route4Green would use its second engine (pickupdrop, first-mile, last-mile with window priority), and time windows are sent to the core as hard windows when tour_mode position 4 is 1. Omit it for the default choice.
core_transport_modestringNoWith engine 'core' only: the optimization core's own transport mode number to plan in, instead of the one derived from the orders' transport_mode (for example '21'). For internal measurement of the core.

Fields of vehicles

FieldTypeRequiredDescription
external_vehicle_idstringYesClient-scoped external vehicle identifier. Must be unique among ACTIVE jobs for this client.
resource_idnumberYesVehicle type ID. The optimizer plans the load against the payload and cargo box of this type, not against vehicle_tonnage, so pick the type that matches the real vehicle
from_addressstringYesStarting address of the vehicle
from_latnumberYesStarting point latitude
from_lonnumberYesStarting point longitude
from_working_timestring (date-time)YesEarliest time the vehicle is available to depart
to_working_timestring (date-time)YesLatest time the vehicle is available to return
handling_unit_idsnumber[]YesHandling unit IDs supported by the vehicle
height_of_vehiclenumberYesInterior height of the vehicle, in centimetres
length_of_vehiclenumberYesInterior length of the vehicle, in centimetres
width_of_vehiclenumberYesInterior width of the vehicle, in centimetres
vehicle_tonnagenumberYesMaximum payload of the vehicle, in kilograms. On first-mile and last-mile, a trip the optimizer loads beyond it is moved to a vehicle that can carry it or reported unassigned with reason OVER_CAPACITY
has_permitbooleanNoWhether the vehicle holds a permit for restricted hours and zones (truck bans). Default false. A vehicle without a permit is never planned at a point inside that point's forbidden_time_windows
to_addressstringNoEnding address of the vehicle, if different from from_address
to_latnumberNoEnding point latitude
to_lonnumberNoEnding point longitude

Fields of orders

FieldTypeRequiredDescription
external_order_idstringYesClient-scoped external order identifier. Must be unique among ACTIVE jobs for this client, and unique within this request.
external_referencestringNoThe partner's own waybill/reference for this order, distinct from external_order_id. Echoed on every result stop and unassigned order.
transport_modefirstmile | midmile | lastmile | pickupdropYesLeg of the order this job should optimize. lastmile: depot to customer; firstmile: customer to hub; midmile: hub to hub; pickupdrop: each order is picked up at its own point A and dropped at its own point B, so one route can mix deliveries and collections. Measurement keys accept lastmile only, sales and trial measurement keys also firstmile and pickupdrop; one mode per job.
depot_refstringNoWhich entry of depots[] is this order's depot end: its pickup on lastmile, its drop on firstmile; that end's address and coordinates are then left out. 'auto' lets Route4Green pick the nearest depot by road time (straight line when the road engine is unavailable). Only for lastmile and firstmile orders.
handling_unit_idnumberYesInternal handling unit ID for this order
service_idnumberYesInternal service ID for this order
resource_idnumberNoInternal resource ID pre-assigned to this order, if any
distancenumberNoKnown distance for this order, in kilometres
pickup_addressstringNoPickup address. Required unless depot_ref is set on a lastmile order
pickup_latnumberNoPickup point latitude. Required unless depot_ref is set on a lastmile order
pickup_lonnumberNoPickup point longitude. Required unless depot_ref is set on a lastmile order
pickup_widnumberNoPickup warehouse/inventory ID, if applicable
pickup_date_timestring (date-time)YesStart of the pickup time window
pickup_date_time_tostring (date-time)YesEnd of the pickup time window
drop_addressstringNoDrop-off address. Required unless depot_ref is set on a firstmile order
drop_latnumberNoDrop-off point latitude. Required unless depot_ref is set on a firstmile order
drop_lonnumberNoDrop-off point longitude. Required unless depot_ref is set on a firstmile order
drop_widnumberNoDrop-off warehouse/inventory ID, if applicable
drop_date_timestring (date-time)YesStart of the drop-off time window
drop_date_time_tostring (date-time)YesEnd of the drop-off time window
loading_timenumberNoTime reserved for loading, in minutes
unloading_timenumberNoTime reserved for unloading, in minutes
max_vehicle_weightnumberNoHeaviest vehicle the customer's point admits, in kilograms of payload, compared with the vehicle_tonnage of each vehicle; 0 or absent means no limit. The point is the drop, or the pickup when the drop is a vehicle depot. Held as a hard rule on plans made by the second engine, which takes every last-mile job carrying this field (production, sales and trial keys; see applied_constraints in the result); an order no vehicle is light enough for is unassigned with reason VEHICLE_TOO_HEAVY. Jobs with optimization_options.engine 'core' only pass it to the optimization core
forbidden_time_windowsstring[]NoUp to two local time ranges (HH:mm-HH:mm, in the client's time zone; a range may run past midnight, such as 21:00-06:00) in which vehicles without a permit (has_permit) may not serve the customer's point (truck ban). Held as a hard rule on plans made by the second engine (see max_vehicle_weight and applied_constraints in the result): the service at the point starts and ends outside the ranges, or the point goes to a permit vehicle; a vehicle that arrives early waits before the point. An order with no open hour and no permit vehicle is unassigned with reason FORBIDDEN_HOURS. Driving through a restricted area without stopping is not checked. Jobs with optimization_options.engine 'core' only pass it to the optimization core
rlengthnumberYesParcel length, in centimetres
rwidthnumberYesParcel width, in centimetres
rheightnumberYesParcel height, in centimetres
rweightnumberYesParcel weight, in kilograms
count_of_parcelsnumberYesNumber of parcels in this order
sender_namestringNoSender name
sender_phonestringNoSender phone number
receiver_namestringNoReceiver name
receiver_phonestringNoReceiver phone number

Fields of depots

FieldTypeRequiredDescription
depot_refstringYesYour id of the depot, referenced by orders[].depot_ref
addressstringYesDepot address
latnumberYesDepot latitude
lonnumberYesDepot longitude

Fields of baseline

FieldTypeRequiredDescription
km_typeroad | straight_lineYesHow the baseline distances were measured: 'road' (road network distance) or 'straight_line' (as the crow flies). Distance deltas are only reported for 'road'.
includes_return_to_depotbooleanYesWhether each baseline distance_km includes the return leg to the depot
routesRouteOptimizationBaselineRouteDto[]YesThe partner's own plan for the same orders, one entry per planned route. Orders absent from every route are the baseline's unassigned orders.
km_basisreported | remeasureNoWhich km the comparison uses. 'reported' (default) compares the submitted distance_km against the Route4Green route distances. 'remeasure' measures both plans as closed loops from the depot on the same self-hosted road engine (OSRM) and compares those; the reported figures are used instead when the road engine is unavailable.
sequence_knownbooleanNoWhether each route's order_ids list the real stop order (default true). false means the order is not known, so baseline routes are not remeasured.
7 fieldsCreateRouteOptimizationJobDto

Responses

202Public job aggregate committed, wrapped in the success envelope; read it at data
400ROUTE_OPT_VALIDATION_ERROR or DUPLICATE_EXTERNAL_ID. Sandbox keys are limited to small last-mile jobs. Measurement keys (free one-day measurement) additionally answer ROUTE_OPT_MEASUREMENT_LIMIT_EXCEEDED (more than 300 orders or 50 vehicles), ROUTE_OPT_MEASUREMENT_SCOPE_UNSUPPORTED (not exactly one last-mile date; sales and trial keys may send one first-mile or pickupdrop date instead) or ROUTE_OPT_MEASUREMENT_PERSONAL_DATA (sender/receiver name or phone present). The baseline is optional for every key
409IDEMPOTENCY_CONFLICT, ACTIVE_EXTERNAL_ID_CONFLICT, or JOB_ALREADY_PROCESSING
413ROUTE_OPT_PAYLOAD_TOO_LARGE
429ROUTE_OPT_RATE_LIMITED, ROUTE_OPT_MONTHLY_LIMIT_REACHED (sandbox keys) or ROUTE_OPT_MEASUREMENT_QUOTA_EXHAUSTED (measurement keys: lifetime job cap per client; jobs that failed on the Route4Green side are not counted)

Back to group: Route optimisation

POST /addons/route-optimization/jobs | Route4Green