Chuyển đến nội dung chính
Mục lục tài liệu
POST

/addons/route-optimization/jobs

Submit an asynchronous route optimization job

Mở trong ChatGPTMở trong Claude

Đường dẫn

POST/api/v1/partners/addons/route-optimization/jobs
Xác thực yêu cầuapi-key

Ví dụ gọi bằng curl

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
  }
}'

Tham số

TênVị tríKiểuBắt buộcMô tả
Idempotency-KeyheaderstringCóClient-scoped key retained indefinitely; maximum 128 chars

Nội dung gửi lên

TrườngKiểuBắt buộcMô tả
external_referencestringKhôngClient-supplied identifier for this job, echoed back on every read
replaces_job_idstring (uuid)KhôngJob 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_optionsobjectCóOptimization mode and delivery/planning settings
vehiclesobject[]CóVehicles available for this job
ordersobject[]CóOrders to assign and sequence across the given vehicles
depotsobject[]KhôngDepots the orders may start from (lastmile) or end at (firstmile), referenced by orders[].depot_ref. Vehicles keep their own start points.
baselineobjectKhôngThe 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.

Các trường của optimization_options

TrườngKiểuBắt buộcMô tả
delivery_mode1 | 2 | 3 | 4CóDelivery mode. 1: normal, 2: same day delivery, 3: express 2H delivery, 4: 4H delivery
kind_of_plan1 | 2CóPlanning mode. 1: actual planning, 2: plan in advance
tour_modestringCóOptimization 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_firstKhôngStop 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 | balancedKhôngHow 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'.
enginecoreKhôngForce 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_modestringKhôngWith 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.

Các trường của vehicles

TrườngKiểuBắt buộcMô tả
external_vehicle_idstringCóClient-scoped external vehicle identifier. Must be unique among ACTIVE jobs for this client.
resource_idnumberCóVehicle 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_addressstringCóStarting address of the vehicle
from_latnumberCóStarting point latitude
from_lonnumberCóStarting point longitude
from_working_timestring (date-time)CóEarliest time the vehicle is available to depart
to_working_timestring (date-time)CóLatest time the vehicle is available to return
handling_unit_idsnumber[]CóHandling unit IDs supported by the vehicle
height_of_vehiclenumberCóInterior height of the vehicle, in centimetres
length_of_vehiclenumberCóInterior length of the vehicle, in centimetres
width_of_vehiclenumberCóInterior width of the vehicle, in centimetres
vehicle_tonnagenumberCóMaximum 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_permitbooleanKhôngWhether 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_addressstringKhôngEnding address of the vehicle, if different from from_address
to_latnumberKhôngEnding point latitude
to_lonnumberKhôngEnding point longitude

Các trường của orders

TrườngKiểuBắt buộcMô tả
external_order_idstringCóClient-scoped external order identifier. Must be unique among ACTIVE jobs for this client, and unique within this request.
external_referencestringKhôngThe 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 | pickupdropCóLeg 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_refstringKhôngWhich 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_idnumberCóInternal handling unit ID for this order
service_idnumberCóInternal service ID for this order
resource_idnumberKhôngInternal resource ID pre-assigned to this order, if any
distancenumberKhôngKnown distance for this order, in kilometres
pickup_addressstringKhôngPickup address. Required unless depot_ref is set on a lastmile order
pickup_latnumberKhôngPickup point latitude. Required unless depot_ref is set on a lastmile order
pickup_lonnumberKhôngPickup point longitude. Required unless depot_ref is set on a lastmile order
pickup_widnumberKhôngPickup warehouse/inventory ID, if applicable
pickup_date_timestring (date-time)CóStart of the pickup time window
pickup_date_time_tostring (date-time)CóEnd of the pickup time window
drop_addressstringKhôngDrop-off address. Required unless depot_ref is set on a firstmile order
drop_latnumberKhôngDrop-off point latitude. Required unless depot_ref is set on a firstmile order
drop_lonnumberKhôngDrop-off point longitude. Required unless depot_ref is set on a firstmile order
drop_widnumberKhôngDrop-off warehouse/inventory ID, if applicable
drop_date_timestring (date-time)CóStart of the drop-off time window
drop_date_time_tostring (date-time)CóEnd of the drop-off time window
loading_timenumberKhôngTime reserved for loading, in minutes
unloading_timenumberKhôngTime reserved for unloading, in minutes
max_vehicle_weightnumberKhôngHeaviest 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[]KhôngUp 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
rlengthnumberCóParcel length, in centimetres
rwidthnumberCóParcel width, in centimetres
rheightnumberCóParcel height, in centimetres
rweightnumberCóParcel weight, in kilograms
count_of_parcelsnumberCóNumber of parcels in this order
sender_namestringKhôngSender name
sender_phonestringKhôngSender phone number
receiver_namestringKhôngReceiver name
receiver_phonestringKhôngReceiver phone number

Các trường của depots

TrườngKiểuBắt buộcMô tả
depot_refstringCóYour id of the depot, referenced by orders[].depot_ref
addressstringCóDepot address
latnumberCóDepot latitude
lonnumberCóDepot longitude

Các trường của baseline

TrườngKiểuBắt buộcMô tả
km_typeroad | straight_lineCóHow 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_depotbooleanCóWhether each baseline distance_km includes the return leg to the depot
routesRouteOptimizationBaselineRouteDto[]CóThe 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 | remeasureKhôngWhich 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_knownbooleanKhôngWhether 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 trườngCreateRouteOptimizationJobDto

Kết quả trả về

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)

Về nhóm: Tối ưu tuyến đường

POST /addons/route-optimization/jobs | Route4Green