Mục lục tài liệu
POST
/addons/route-optimization/jobs
Submit an asynchronous route optimization job
Đường dẫn
POST
/api/v1/partners/addons/route-optimization/jobsXác thực yêu cầu
api-keyVí 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ên | Vị trí | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|---|
| Idempotency-Key | header | string | Có | Client-scoped key retained indefinitely; maximum 128 chars |
Nội dung gửi lên
| Trường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| external_reference | string | Không | Client-supplied identifier for this job, echoed back on every read |
| replaces_job_id | string (uuid) | Không | Job 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_options | object | Có | Optimization mode and delivery/planning settings |
| vehicles | object[] | Có | Vehicles available for this job |
| orders | object[] | Có | Orders to assign and sequence across the given vehicles |
| depots | object[] | Không | Depots the orders may start from (lastmile) or end at (firstmile), referenced by orders[].depot_ref. Vehicles keep their own start points. |
| baseline | object | Không | The 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ường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| delivery_mode | 1 | 2 | 3 | 4 | Có | Delivery mode. 1: normal, 2: same day delivery, 3: express 2H delivery, 4: 4H delivery |
| kind_of_plan | 1 | 2 | Có | Planning mode. 1: actual planning, 2: plan in advance |
| tour_mode | string | Có | 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_order | mixed | deliveries_first | Không | Stop 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_trips | multiple | single | balanced | Không | How 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'. |
| engine | core | Không | Force 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_mode | string | Không | With 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ường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| external_vehicle_id | string | Có | Client-scoped external vehicle identifier. Must be unique among ACTIVE jobs for this client. |
| resource_id | number | Có | 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_address | string | Có | Starting address of the vehicle |
| from_lat | number | Có | Starting point latitude |
| from_lon | number | Có | Starting point longitude |
| from_working_time | string (date-time) | Có | Earliest time the vehicle is available to depart |
| to_working_time | string (date-time) | Có | Latest time the vehicle is available to return |
| handling_unit_ids | number[] | Có | Handling unit IDs supported by the vehicle |
| height_of_vehicle | number | Có | Interior height of the vehicle, in centimetres |
| length_of_vehicle | number | Có | Interior length of the vehicle, in centimetres |
| width_of_vehicle | number | Có | Interior width of the vehicle, in centimetres |
| vehicle_tonnage | number | Có | 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_permit | boolean | Không | Whether 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_address | string | Không | Ending address of the vehicle, if different from from_address |
| to_lat | number | Không | Ending point latitude |
| to_lon | number | Không | Ending point longitude |
Các trường của orders
| Trường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| external_order_id | string | Có | Client-scoped external order identifier. Must be unique among ACTIVE jobs for this client, and unique within this request. |
| external_reference | string | Không | The partner's own waybill/reference for this order, distinct from external_order_id. Echoed on every result stop and unassigned order. |
| transport_mode | firstmile | midmile | lastmile | pickupdrop | Có | 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_ref | string | Không | Which 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_id | number | Có | Internal handling unit ID for this order |
| service_id | number | Có | Internal service ID for this order |
| resource_id | number | Không | Internal resource ID pre-assigned to this order, if any |
| distance | number | Không | Known distance for this order, in kilometres |
| pickup_address | string | Không | Pickup address. Required unless depot_ref is set on a lastmile order |
| pickup_lat | number | Không | Pickup point latitude. Required unless depot_ref is set on a lastmile order |
| pickup_lon | number | Không | Pickup point longitude. Required unless depot_ref is set on a lastmile order |
| pickup_wid | number | Không | Pickup warehouse/inventory ID, if applicable |
| pickup_date_time | string (date-time) | Có | Start of the pickup time window |
| pickup_date_time_to | string (date-time) | Có | End of the pickup time window |
| drop_address | string | Không | Drop-off address. Required unless depot_ref is set on a firstmile order |
| drop_lat | number | Không | Drop-off point latitude. Required unless depot_ref is set on a firstmile order |
| drop_lon | number | Không | Drop-off point longitude. Required unless depot_ref is set on a firstmile order |
| drop_wid | number | Không | Drop-off warehouse/inventory ID, if applicable |
| drop_date_time | string (date-time) | Có | Start of the drop-off time window |
| drop_date_time_to | string (date-time) | Có | End of the drop-off time window |
| loading_time | number | Không | Time reserved for loading, in minutes |
| unloading_time | number | Không | Time reserved for unloading, in minutes |
| max_vehicle_weight | number | Không | Heaviest 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_windows | string[] | Không | Up 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 |
| rlength | number | Có | Parcel length, in centimetres |
| rwidth | number | Có | Parcel width, in centimetres |
| rheight | number | Có | Parcel height, in centimetres |
| rweight | number | Có | Parcel weight, in kilograms |
| count_of_parcels | number | Có | Number of parcels in this order |
| sender_name | string | Không | Sender name |
| sender_phone | string | Không | Sender phone number |
| receiver_name | string | Không | Receiver name |
| receiver_phone | string | Không | Receiver phone number |
Các trường của depots
| Trường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| depot_ref | string | Có | Your id of the depot, referenced by orders[].depot_ref |
| address | string | Có | Depot address |
| lat | number | Có | Depot latitude |
| lon | number | Có | Depot longitude |
Các trường của baseline
| Trường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| km_type | road | straight_line | Có | 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_depot | boolean | Có | Whether each baseline distance_km includes the return leg to the depot |
| routes | RouteOptimizationBaselineRouteDto[] | 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_basis | reported | remeasure | Không | Which 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_known | boolean | Không | Whether 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 data400ROUTE_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 key409IDEMPOTENCY_CONFLICT, ACTIVE_EXTERNAL_ID_CONFLICT, or JOB_ALREADY_PROCESSING413ROUTE_OPT_PAYLOAD_TOO_LARGE429ROUTE_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)