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

/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.

Mở trong ChatGPTMở trong Claude

Đường dẫn

POST/api/v1/partners/addons/route-optimization/jobs/{jobId}/insertions
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/{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ênVị tríKiểuBắt buộcMô tả
jobIdpathstring (uuid)Có
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 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_atstring (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_idsstring[]KhôngOrders of the earlier job already delivered. When sent, it replaces the time rule for deliveries: a delivery is done only if listed here.
vehicle_positionsobject[]KhôngWhere vehicles are at inserted_at. A vehicle not listed is taken to be at its last done stop.
ordersobject[]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ườngKiểuBắt buộcMô tả
external_vehicle_idstringCóexternal_vehicle_id of a vehicle of the earlier job
latnumberCó
lonnumberCó

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
5 trườngCreateRouteOptimizationInsertionDto

Kết quả trả về

202The new job, wrapped in the success envelope; read its result at GET /jobs/:id/result
400ROUTE_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 keys
404ROUTE_OPT_JOB_NOT_FOUND
409ROUTE_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_CONFLICT
410RESULT_PURGED: the job data was deleted after retention
429ROUTE_OPT_RATE_LIMITED or ROUTE_OPT_MEASUREMENT_QUOTA_EXHAUSTED

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

POST /addons/route-optimization/jobs/{jobId}/insertions | Route4Green