Mục lục tài liệu
/addons/route-optimization/jobs/{jobId}/insertions
Insert urgent orders into a finished job (mid-day insertion)
Creates a new job over the whole day of the given job: stops done by inserted_at (or listed in completed_order_ids) stay as they were, the remaining stops of each vehicle keep their order, and each urgent order goes where it adds the least driving while load, windows and working hours still hold. An urgent order is loaded at its depot, so the vehicle calls there unless it has not left yet. Earlier orders do not move to another vehicle. The result carries inserted_into_job_id, inserted_orders (added_km, added_minutes), changed per route, and locked and inserted per stop; an urgent order that fits nowhere is in unassigned_order_references with reason OVER_CAPACITY, WINDOW_MISSED or NO_VEHICLE_TIME. Counts as one run. Production keys and sales or trial measurement keys only.
Đường dẫn
/api/v1/partners/addons/route-optimization/jobs/{jobId}/insertionsapi-keyVí dụ gọi bằng curl
curl -X POST "https://api.route4green.com/api/v1/partners/addons/route-optimization/jobs/{jobId}/insertions" \
-H "api-key: YOUR_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "content-type: application/json" \
-d '{
"external_reference": "string",
"inserted_at": "2026-01-01T00:00:00+07:00",
"completed_order_ids": [
"string"
],
"vehicle_positions": [
{
"external_vehicle_id": "string",
"lat": 0,
"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"
}
]
}'Tham số
| Tên | Vị trí | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|---|
| jobId | path | string (uuid) | Có | |
| 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 the new job, echoed back on every read. Absent or blank: the new job keeps the external_reference of the job it inserts into |
| inserted_at | string (date-time) | Có | When the urgent orders are inserted (ISO 8601). Stops of the earlier plan that finish by then count as done unless completed_order_ids is sent. |
| completed_order_ids | string[] | Không | Orders of the earlier job already delivered. When sent, it replaces the time rule for deliveries: a delivery is done only if listed here. |
| vehicle_positions | object[] | Không | Where vehicles are at inserted_at. A vehicle not listed is taken to be at its last done stop. |
| orders | object[] | Có | Urgent last-mile orders, picked up at a depot and delivered on the same date as the earlier job. Same fields as orders of POST /jobs; ids must not repeat the earlier job. |
Các trường của vehicle_positions
| Trường | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| external_vehicle_id | string | Có | external_vehicle_id of a vehicle of the earlier job |
| lat | number | Có | |
| lon | number | Có |
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 |
Kết quả trả về
202The new job, wrapped in the success envelope; read its result at GET /jobs/:id/result400ROUTE_OPT_VALIDATION_ERROR (an urgent order not lastmile, with depot_ref, or on another date; an unknown order in completed_order_ids or vehicle in vehicle_positions) or DUPLICATE_EXTERNAL_ID (an urgent order id repeats, or is an order of the job)403ROUTE_OPT_INSERTION_NOT_AVAILABLE: sandbox keys and free or self-serve measurement keys404ROUTE_OPT_JOB_NOT_FOUND409ROUTE_OPT_INSERTION_JOB_NOT_FINISHED (the job is not SUCCEEDED or PARTIAL), ROUTE_OPT_INSERTION_UNSUPPORTED (not one last-mile date), IDEMPOTENCY_CONFLICT or ACTIVE_EXTERNAL_ID_CONFLICT410RESULT_PURGED: the job data was deleted after retention429ROUTE_OPT_RATE_LIMITED or ROUTE_OPT_MEASUREMENT_QUOTA_EXHAUSTED