Optimize Route by Distance
This API call enables the optimization of an individual’s daily route. It intelligently reorders jobs to create an optimized route, focusing on minimizing travel distance while prioritizing high-priority jobs. This optimization process is immediate, requiring no additional saving or editing actions. If the date is set to today, workers will be promptly notified of their updated job order.Key Features:
- Priority and Distance Focused: Prioritizes high-priority jobs while minimizing the overall travel distance.
- Dynamic Route Start/End Points:
- Primarily, the worker’s specified start/end locations are used.
- If not set, the team’s start location is considered.
- In the absence of both, the first and last jobs of the day determine the route’s endpoints.
- Route Start Time: Determined based on the worker’s specified working hours.
- Travel mode: Determined based on the worker’s travel mode setting (Car, Bicycle, Pedestrian, Truck, Van, Motorcycle).
Note:
- Currently, this route optimization does not support specific time windows for jobs or locations.
- Route optimization naturally only works if all jobs are accessible via car or any vehicle.
- Also see:
/distributejobsand/autoassignendpoints.
REQUEST
The date in number format: YYYYMMDD, e.g. 20221125 equals to Nov 25, 2022.
Worker’s UID or username.
If
true, uses advanced route solving with constraints (time windows, skills, capacity). If false, performs simple distance-based optimization. Solving mode may result in some jobs being unassigned if constraints cannot be satisfied.Starting index for partial route optimization. Use with
count to optimize only a subset of jobs in the route.Number of jobs to include in partial route optimization, starting from
index.Constraint configuration for route solving (only applies when
solve: true):working_hours(boolean, default: true): Respect worker’s working hourstime_window(boolean, default: true): Honor job time windowsskills(boolean, default: true): Match required skills with worker capabilitiescapacity(boolean, default: true): Consider pickup/dropoff capacity limitsmax_jobs(number, default: 1000): Maximum number of jobs to process
RESPONSE
Status code.
0 indicates success, other values indicate errors (e.g., permission denied).The newly arranged jobs representing the optimized route (includes full job objects).
Array of job IDs in their original order before optimization. Useful for implementing undo functionality.
Array of job IDs that could not be assigned during route solving (only present when
solve: true). These jobs couldn’t be included due to constraint violations (e.g., time windows, capacity, skills mismatch).true if a route optimization was successfully calculated and applied.Only present when route solving fails. Possible values:
no_region: No routing region available for the locationimpossible_route: Route cannot be calculated with given constraintsinternal_error: Server-side error during optimizationinput_error: <details>: Invalid input parametersrouting_error: <details>: Error from routing service
Permissions
Route optimization requires appropriate permissions:- Administrators and company owners can always optimize routes
- Dispatchers can optimize routes for their team members
- Workers can optimize their own routes if the
workers_optimize_routesetting is enabled
Caching & Throttling
- Recently optimized routes (within 3 hours) may be returned from cache for worker requests
- Reduces unnecessary recomputation when multiple optimization requests are made