Skip to main content
Docs menu
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.

Path

POST/api/v1/partners/addons/route-optimization/jobs/{jobId}/insertions
Authentication requiredapi-key

curl example

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

Parameters

NameInTypeRequiredDescription
jobIdpathstring (uuid)Yes
Idempotency-KeyheaderstringYesClient-scoped key retained indefinitely; maximum 128 chars

Request body

FieldTypeRequiredDescription
external_referencestringNoClient-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)YesWhen 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[]NoOrders 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[]NoWhere vehicles are at inserted_at. A vehicle not listed is taken to be at its last done stop.
ordersobject[]YesUrgent 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.

Fields of vehicle_positions

FieldTypeRequiredDescription
external_vehicle_idstringYesexternal_vehicle_id of a vehicle of the earlier job
latnumberYes
lonnumberYes

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
5 fieldsCreateRouteOptimizationInsertionDto

Responses

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

Back to group: Route optimisation

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