Initialize Vehicle Based Route Optimization


This section relates to Initialize Auto-Dispatch Route Optimization , which requires Route Plans to be enabled and may depend on your Onfleet subscription plan. For details on feature availability, please contact [email protected].

Using this endpoint initializes a standard scheduled route optimization workflow and creates routes for generic vehicles, rather than assigning them directly to drivers. The request requires route optimization (RO) parameters and will respond with any issues. If successful, it returns a summary and an ID for the next step in the optimization process.

Once everything is set up and confirmed, use Start Route Optimization to initiate the calculation.

Note: If you are using the v3 optimization engine, you can specify multiple vehicle types. The classic optimization engine can consider only one vehicle type at a time.

JSON payload fields for setting up the RO using vehicle:

Initial base field: jobType:

NameTypeDescription
jobTypestringRequired. The only acceptable value here is DEFAULT

Other base fields:

NameTypeDescription
optimizationTypestringRequired. The only acceptable value here is VEHICLES.
maxTasksPerRoutenumberRequired. How many tasks should be assigned to each worker. This overrides the per vehicle
dateTime in UnixRequired. This will need to be in milliseconds precision and will need to be aligned with the completeBefore and completeAfter time range specified on the individual task.
timezonestringRequired. Which timezone is considered.
modenumberRequired. This corresponds to the Optimization mode on the Dashboard. Put 0 for Minimize Distance Driven, 1 Always Arrive On Time and 2 for Balance Distance and Time.
serviceTimenumberRequired. How many minutes a driver would spend on each task. This will adds to the time calculation of the RO and is considered part of the delivery time.
tasksArray of Task ObjectsRequired. Task IDs to be considered for the RO.
teamsObjectRequired. The Team IDs and their associated workers' ID for Route Optimization to consider.
schedulingMethodnumberRequired. Which schedule would be used for the RO to consider; put 0 for default schedule, put 1 for Driver's Schedule.
routeStartstringWhere the Route should start.
routeEndstringWhere the Route would end.
maxViolationTimenumberTime in minutes that the RO should consider. This is important if mode is Always arrive on Time. Will result in
avoidTollsbooleanShould the RO considered toll roads.
balanceRoutesbooleanShould the RO consider balance tasks across all drivers
allowMissingLinkedTasksbooleanShould the RO consider missing Linked-Tasks.
createEndRouteTaskbooleanShould the RO create an End route Task at the Hub
optimizationByVehicleObjectRequired. Please see below for further explanation.
defaultScheduleObjectPlease see Get worker's schedule for how Schedule object looks like.

The distinguished part of this RO by API section

optimizationByVehicle Object:

NameTypeDescription
teamstringThe Team IDs and their associated workers' ID for Route Optimization to consider.
vehicleTypesObjectPlease see below examples for the breakdown of this object

For thevehicleTypes Object field, you must include all of the fields listed in the table below:

NameTypeDescription
walkingObjectRequired. See below for further explanation
bicycleObjectRequired. See below for further explanation
motorcycleObjectRequired. See below for further explanation
carObjectRequired. See below for further explanation
truckObjectRequired. See below for further explanation

each one of the vehicle types are required, and they all have the same following fields:

NameTypeDescription
selectedbooleanThis field determines what types of vehicle(s) would be considered for the RO. Put true if you would like to include this vehicle type; put false to leave it off.
countnumberHow many vehicles of this type should be considered for the RO.
maxTasksPerRoutenumberHow many tasks for each of the drivers considered for the RO.
capacitynumberHow many capacity each vehicle has it.
{
    "jobType": "DEFAULT",
    "optimizationType": "VEHICLES",
    "maxTasksPerRoute": 0,
    "date": 1761779759419,
    "timezone": "America/Los_Angeles",
    "mode": 1,
    "serviceTime": 30,
    "tasks":
    [
        "iHz~bG*Esph92oQRS*53p~6w",
        "uNVNORDYNfGzMsH5Jt3n48F3",
        "ZSfzR90IeDJrjxWBLHbboOjA",
        "NUv5ZPWDGMvQd*~x1d8EPRCI"
    ],
    "teams":
    {},
    "schedulingMethod": 1,
    "routeStart": "hub://FK9Uny9sQzcvBmEqHXqwWSeV",
    "routeEnd": "hub://FK9Uny9sQzcvBmEqHXqwWSeV",
    "maxViolationTime": 3,
    "avoidTolls": true,
    "balanceRoutes": true,
    "allowMissingLinkedTasks": false,
    "createEndRouteTask": false,
    "optimizationByVehicle":
    {
        "team": null,
        "vehicleTypes":
        {
            "walking":
            {
                "selected": false,
                "count": null,
                "maxTasksPerRoute": null,
                "capacity": null
            },
            "bicycle":
            {
                "selected": false,
                "count": null,
                "maxTasksPerRoute": null,
                "capacity": null
            },
            "motorcycle":
            {
                "selected": false,
                "count": null,
                "maxTasksPerRoute": null,
                "capacity": null
            },
            "car":
            {
                "selected": true,
                "count": 1,
                "maxTasksPerRoute": 5,
                "capacity": 1
            },
            "truck":
            {
                "selected": false,
                "count": null,
                "maxTasksPerRoute": null,
                "capacity": null
            }
        }
    },
    "defaultSchedule":
    [
        {
            "date": 1761779759419,
            "owner": "nYrkNP6jZMSKgBwG9qG7ci3J",
            "timezone": "America/Los_Angeles",
            "slots":
            [
                {
                    "start": "0900",
                    "end": "2359"
                }
            ]
        }
    ]
}
{
    "id": "j6BWjQvO31tofLgktcNcnqGQ",
    "issues": [
        {
            "type": "warning",
            "message": "Task b96426cc is more than 200 miles (321 KM) away from any hub.",
            "entityType": "task",
            "entityId": "iHz~bG*Esph92oQRS*53p~6w",
            "shortId": "b96426cc",
            "reason": "too-far-from-hub"
        },
        {
            "type": "warning",
            "message": "Task 43dca744 is more than 200 miles (321 KM) away from any hub.",
            "entityType": "task",
            "entityId": "uNVNORDYNfGzMsH5Jt3n48F3",
            "shortId": "43dca744",
            "reason": "too-far-from-hub"
        },
        {
            "type": "warning",
            "message": "Task 0fcd5716 is more than 200 miles (321 KM) away from any hub.",
            "entityType": "task",
            "entityId": "ZSfzR90IeDJrjxWBLHbboOjA",
            "shortId": "0fcd5716",
            "reason": "too-far-from-hub"
        }
    ],
    "summary": {
        "workers": {
            "count": 0
        },
        "tasks": {
            "count": 4,
            "cost": 0.4
        },
        "routeZones": {
            "count": 0
        },
        "vehicles": {
            "bicycle": 0,
            "car": 1,
            "motorcycle": 0,
            "truck": 0,
            "walking": 0
        },
        "total": 0.4
    },
    "shortId": "ae9667659200dbfe"
}