You are viewing Nextmv legacy docs. ⚡️ Go to latest docs ⚡️

Cloud

Onfleet

You will learn how to use the Onfleet integration.

Onfleet is a logistics software focused on dispatch and fleet management. You can leverage the power of Nextmv's Cloud API with the Onfleet integration. This integration offers functionality for interacting with the Onfleet API and leveraging Nextmv's extended optimization and routing features. The following entities are fetched and transformed from Onfleet API → Nextmv Cloud API:

Once the entities have been transformed, the stops are routed and assigned to the vehicles and the final assignments are represented as Onfleet containers.

Endpoints

Note, all requests must be authenticated with Bearer Authentication. Make sure your request has a header containing your Nextmv Cloud API key, as such:

  • Key: Authorization
  • Value: Bearer <YOUR-API-KEY>
Authorization: Bearer <YOUR-API-KEY>
Copy
POSThttps://api.cloud.nextmv.io/v1/routing/profiles/integration/onfleet

Create a new Onfleet integration.

Create a new Onfleet integration. Onfleet is the source of the truth for tasks (stops) and workers (vehicles). Entities are fetched from the Onfleet API and containers (assignments) are created for the user to upload them to the Onfleet API. Use the `id` of the integration to manage it (using the `GET`, `PUT` and `DELETE` endpoints that follow).

GEThttps://api.cloud.nextmv.io/v1/routing/profiles/integration/onfleet/{integration_id}

Get an existing Onfleet integration.

Get an existing Onfleet integration using the `id` associated with it.

PUThttps://api.cloud.nextmv.io/v1/routing/profiles/integration/onfleet/{integration_id}

Modify an existing Onfleet integration.

Modify an existing Onfleet integration using the `id` associated with it.

DELETEhttps://api.cloud.nextmv.io/v1/routing/profiles/integration/onfleet/{integration_id}

Delete an existing Onfleet integration.

Delete an existing Onfleet integration using the `id` associated with it.

POSThttps://api.cloud.nextmv.io/v1/integrations/onfleet/run

Create a new run specific for Onfleet tasks and workers.

Request a new run to the Nextmv Cloud API, specific for Onfleet tasks and workers. Similar to the `v0/run` endpoint, you will obtain a `run_id` that you can use to query your status and results using the `v0/status` and `v0/result` endpoints, respectively. Make sure that you have an existing Onfleet integration configured and a run profile that uses that integration. The tasks and workers that are referenced must exist in the Onfleet API.

GEThttps://api.cloud.nextmv.io/v0/run/{run_id}/status

Get a run status.

Poll the status of the run requested with the `/v0/run` endpoint, using the `run_id` obtained. If the status is `succeeded`, it means that the solution can be queried using the `/v0/run/{run_id}/result` endpoint.

GEThttps://api.cloud.nextmv.io/v0/run/{run_id}/result

Get the result of the run.

Get the result of the run requested with the `/v0/run` endpoint, using the `run_id` obtained. The solution can be found under the `state` key.

For the full specification, please visit the Nextmv Cloud API OpenAPI specification.

Using the integration

  • Nextmv will not push any information to the Onfleet API on your behalf. The integration is read-only.
  • Onfleet is considered to be the source of truth for tasks (stops) and workers (vehicles).
  • We highly recommend reading the using the Nextmv Cloud API section given that using the Onfleet integration follows a very similar logic.
  1. Create the tasks and workers you want to route. To leverage the full feature set of the Nextmv Cloud API, please check out the following sections:

  2. Get the Nextmv and Onfleet API keys. This only needs to be done once.

  3. Set up an Onfleet integration on Nextmv to securely store the Onfleet API key.

  4. Create a run profile for using the Onfleet integration when requesting new runs, using the integration id and type obtained in the previous step. This only needs to be done once.

  5. Send a request to the /v1/integrations/onfleet/run endpoint with a JSON body that follows the input schema to route and assign the desired tasks and workers, using the run profile id obtained in the previous step with the run_profile key. The API server should return a run_id that you will use to query your results. This means that a Nextmv solver has been spun up to solve the model with the given input. The time it takes to finish execution varies by the size of the input and solver options.

  6. Poll the status of your run with the /v0/run/{run_id}/status endpoint, using the run_id. Once the status is succeeded, you can query your results. Please see our section on using the API for more information.

  7. Get the result of your run with the /v0/run/{run_id}/result endpoint, using the run_id. The result holds the Onfleet containers that represent the final assignments of tasks to workers and it will follow the structure of the output schema. Please see our section on using the API for more information.

  8. Update the container's tasks in the Onfleet API using the results optimized by the Nextmv Cloud routing engine.

  9. Manage your configurations using the endpoints.

Note, the Onfleet integration can also be set up and edited through the Nextmv Cloud Console. See the console configuration page for more information.

Set up the integration

The Onfleet integration lets you securely store one or more Onfleet API keys inside of Nextmv Cloud. Send a request to the /v1/routing/profiles/integration/onfleet endpoint with a JSON payload that follows this schema:

KeyDescriptionRequiredSample valueType
nameHuman-readable name to identify the integration key.Yes"Sample Onfleet integration key"string
descriptionA description of the integration.No"Sample Onfleet integration description"string
idID for the Onfleet integration; only lower case letters, numbers, and dashes permitted; max length 32 characters.Yes"onfleet-key"string
configurationObject with the Onfleet configurations you want to set.Yes{ "api_key": "<YOUR_ONFLEET_API_KEY>" }object

The configuration object allows you to securely store your Onfleet API key and optionally set up the compatibility feature explained below.

KeyDescriptionRequiredSample valueType
api_keyOnfleet API key.Yes"<YOUR_ONFLEET_API_KEY>"string
compatibilityFlags to toggle on/off compatible attributes for tasks and workers.No{ "tasks": {"quantity": false}, "workers": {"capacity": false} }object

The compatibility object allows you to fine-tune which task and worker attributes are automatically parsed when supported by compatible functionality. Using the compatibility feature is optional. Any attribute that is not explicitly defined as false will be automatically parsed as true. The object follows this schema:

KeyDescriptionRequiredSample valueType
tasksFlags to toggle on/off compatible Onfleet task attributes when parsing to a Nextmv stop.No{ "service_time": false, "quantity": true }object
workersFlags to toggle on/off compatible Onfleet worker attributes when parsing to a Nextmv vehicle.No{ "capacity": false, "tasks": true }object

In the following two tables you will find the schema definition for the tasks and workers object, respectively.

  • tasks schema (you can read more about compatible Onfleet task attributes here):

    KeyDescriptionRequiredSample valueType
    complete_before_afterParse the Onfleet task's completeBefore and completeAfter into a Nextmv stop's hard_window.Nofalseboolean
    dependenciesParse the Onfleet task's dependencies into Nextmv stop's succeeds.Nofalseboolean
    locationParse the Onfleet task's destination.location into the Nextmv stop's position. NOTE: if you turn this toggle off (false) you should make sure that you are specifying position via task metadata, otherwise your stop will not have a location and will cause an error.Nofalseboolean
    quantityParse the Onfleet task's quantity into the Nextmv stop's quantity.Nofalseboolean
    service_timeParse the Onfleet task's serviceTime into the Nextmv stop's stop_duration.Nofalseboolean
  • workers schema (you can read more about compatible Onfleet worker attributes here):

    KeyDescriptionRequiredSample valueType
    active_taskParse the Onfleet worker's activeTask to be part of the Nextmv vehicle's backlog.Nofalseboolean
    capacityParse the Onfleet worker's capacity into the Nextmv vehicle's capacity.Nofalseboolean
    locationParse the Onfleet worker's location into the Nextmv vehicle's start position.Nofalseboolean
    tasksParse the Onfleet worker's tasks to be part of the Nextmv vehicle's backlog.Nofalseboolean

A sample schema and response are provided below:

{
  "name": "My Onfleet Configuration",
  "description": "my onfleet configuration for deliveries in LA",
  "id": "my-onfleet-integration",
  "configuration": {
    "api_key": "b4**************************8a7",
    "compatibility": {
      "tasks": {
        "quantity": false
      },
      "workers": {
        "active_task": false,
        "tasks": false,
        "capacity": true
      }
    }
  }
}
Copy

Make sure to store the id and type, as you will need them to add the integration to your run profile. Please note that you may set up multiple integration profiles using this method. You only need to do this process once for each API key.

To modify an existing Onfleet integration, you can use the PUT /v1/routing/profiles/integration/onfleet/{profile_id} endpoint with a JSON payload that follows the same schema as when creating a new integration (described in the table above). Note that you may not modify the original id.

Compatible functionality

Onfleet's API offers functionality that is compatible with Nextmv Cloud API. If compatible attributes are defined for tasks and/or workers, they will be parsed to Nextmv features. In the following tables you will find a list of these attributes.

Note, all the compatible fields for tasks and workers are parsed by default. You can toggle off (or back on) the specific fields you would like to automatically parse using the compatibility feature in the Onfleet integration profile.

Task compatible attributes

Onfleet attributeOnfleet typeOnfleet exampleNextmv attributeNextmv type (Go)Nextmv example
completeBefore, completeAfternumber1609522200, 1609529400hard_window[2]time.Time[ "2021-01-01T12:30:00-00:00", "2021-01-01T14:30:00-00:00" ]
dependenciesarray string[ "id-1", "id-2" ]succeeds[]string[ "id-1", "id-2" ]
destination.locationarray number[ 1.23, 4.56 ]positionmap[string]int{ "lon": 1.23, "lat": 4.56 }
quantitynumber10quantityint10
serviceTimenumber5stop_durationint300
  • quantity can be extended to be a multi-quantity.
  • If the field pickupTask on the task is set to true, the quantity will default to be negative, regardless of how it is set.
  • Onfleet serviceTime (minutes) is converted to stop_duration (seconds), given that durations are handled in seconds inside of the Nextmv Cloud API.

Worker compatible attributes

Onfleet attributeOnfleet typeOnfleet exampleNextmv attributeNextmv type (Go)Nextmv example
activeTaskstring"id-1"backlog[]string[ "id-1" ]
capacitynumber100capacityint100
locationarray number[ 2.294223, 48.858591 ]startmap[string]float64{ "lon": 2.294223, "lat": 48.858591 }
tasksarray string[ "id-1", "id-2" ]backlog[]string[ "id-1", "id-2" ]
  • capacity can be extended to be a multi-capacity.
  • activeTask and tasks, if defined, are parsed to be part of the backlog. Additional tasks can be added to the backlog if the worker is extended with the backlog metadata entry.

Extending functionality

To use Nextmv Cloud API features not supported by the Onfleet API, you may extend tasks and workers using Onfleet metadata. Metadata for tasks and workers is defined as an array of metadata objects. The name of each metadata object should follow this pattern:

"nextmv:<version>:<attribute>"
Copy

Where version dictates the metadata version used and attribute is the name of the Nextmv attribute used to extend the task or worker. An example of a name is: "nextmv:0.1:unassigned_penalty", used to set an unassigned penalty for a task (stop). You may use all (or none) supported metadata extensions for both tasks and workers. In the following tables you will find a list of these attributes.

Additional steps are required to ensure expected behavior when using alternate stops with Onfleet.

Task extended attributes

AttributeOnfleet typeOnfleet subtypeNextmv type (Go)Example object
position"object"NAmap[string]float64{ "name": "nextmv:0.1:position", "type": "object", "value": { "lon": 1.23, "lat": 4.56 } }
unassigned_penalty"number"NAint{ "name": "nextmv:0.1:unassigned_penalty", "type": "number", "value": 10500 }
quantity"object"NAmap[string]int{ "name": "nextmv:0.1:quantity", "type": "object", "value": { "volume": 400, "weight": 600 } }
precedes"array""string"[]string{ "name": "nextmv:0.1:precedes", "type": "array", "subtype": "string", "value": [ "id-1", "id-2" ] }
max_wait"number"NAint{ "name": "nextmv:0.1:max_wait", "type": "number", "value": 300 }
target_time"string"NAtime.Time{ "name": "nextmv:0.1:target_time", "type": "string", "value": "2021-10-17T09:45:00-06:00" }
earliness_penalty"number"NAfloat64{ "name": "nextmv:0.1:earliness_penalty", "type": "number", "value": 125.1 }
lateness_penalty"number"NAfloat64{ "name": "nextmv:0.1:lateness_penalty", "type": "number", "value": 125.1 }
compatibility_attributes"array""string"[]string{ "name": "nextmv:0.1:compatibility_attributes", "type": "array", "subtype": "string", "value": [ "comp-1", "comp-2" ] }
  • The example shown for quantity is for multi-capacity. You can use a single capacity dimension, in which case the Onfleet type is "number" and the Nextmv type is int.
  • If quantity is defined in the Onfleet task and through metadata, a multi-quantity type will be used. This applies to both metadata cases: an object with multiple dimensions or a single numerical quantity.
  • The example shown for precedes is for multi-precedes. You can use a single ID for precedes, in which case the Onfleet type is "string" and the Nextmv type is string.

Worker extended attributes

AttributeOnfleet typeOnfleet subtypeNextmv type (Go)Example object
start"object"NAmap[string]float64{ "name": "nextmv:0.1:start", "type": "object", "value": { "lon": 2.294223, "lat": 48.858591 } }
end"object"NAmap[string]float64{ "name": "nextmv:0.1:end", "type": "object", "value": { "lon": 2.294223, "lat": 48.858591 } }
speed"number"NAfloat64{ "name": "nextmv:0.1:speed", "type": "number", "value": 10.3 }
capacity"object"NAmap[string]int{ "name": "nextmv:0.1:capacity", "type": "object", "value": { "volume": 4000, "weight": 6000 } }
shift_start"string"NAtime.Time{ "name": "nextmv:0.1:shift_start", "type": "string", "value": "2021-10-17T09:45:00-06:00" }
shift_end"string"NAtime.Time{ "name": "nextmv:0.1:shift_end", "type": "string", "value": "2021-10-17T09:45:00-06:00" }
compatibility_attributes"array""string"[]string{ "name": "nextmv:0.1:compatibility_attributes", "type": "array", "subtype": "string", "value": [ "comp-1", "comp-2" ] }
max_stops"number"NAint{ "name": "nextmv:0.1:max_stops", "type": "number", "value": 10 }
max_distance"number"NAint{ "name": "nextmv:0.1:max_distance", "type": "number", "value": 1000 }
max_duration"number"NAint{ "name": "nextmv:0.1:max_duration", "type": "number", "value": 3600 }
stop_duration_multiplier"number"NAfloat64{ "name": "nextmv:0.1:stop_duration_multiplier", "type": "number", "value": 1.5 }
backlog"array""string"[]string{ "name": "nextmv:0.1:backlog", "type": "array", "subtype": "string", "value": [ "id-1", "id-2" ] }
alternate_stops"array""string"[]string{ "name": "nextmv:0.1:alternate_stops", "type": "array", "subtype": "string", "value": [ "id-1", "id-2" ] }
initialization_cost"number"NAint{ "name": "nextmv:0.1:initialization_cost", "type": "number", "value": 1500 }
  • For offline workers, their location is null, so you can use the start attribute to define where the route should start. If the starting location is defined through metadata, it overrides the worker's location attribute.
  • You can assign the same start and end to represent routes with depots.
  • The example shown for capacity is for multi-capacity. You can use a single capacity dimension, in which case the Onfleet type is "number" and the Nextmv type is int.
  • If capacity is defined in the Onfleet worker and through metadata, a multi-capacity type will be used. This applies to both metadata cases: an object with multiple dimensions or a single numerical quantity.
  • To specify a worker's shift, please use the shift_start and shift_end metadata attributes. We do not support native Onfleet worker schedules given that they may contain multiple shifts.

Input schema

The input schema is a JSON payload that has the following keys:

KeyDescriptionRequiredType
routingOptions to customize the routing configurations.Yesobject
onfleetSpecification of tasks and workers to route.Yesobject

A sample input is provided as a .json file.

Routing options

The routing options is an object that has the following keys:

KeyDescriptionRequiredType
run_profileObject to select the run profile id you want to use.Yesobject
optionsSelect the solver options that you want to use.Noobject
defaultsSpecify the default override attributes for stops and vehicles.Noobject

A sample routing object is provided as part of the input schema below.

Onfleet specification

The Onfleet specification is an object that has the following keys:

KeyDescriptionRequiredType
tasksObject to specify the tasks you want to route.Yesobject
workersObject to specify the workers you want to route.Yesobject
stop_groupsArray to specify custom stop groups for the routes.Noarray of array of string
alternate_stopsArray of task IDs that are considered alternate stops.Noarray of string
duration_groupsGroup of stops that add an overall service timeNoarray of object
  • Use of alternate stops with Onfleet does involve additional steps to assure that exactly 1 alternate stop is assigned per vehicle's route. When using alternate_stops it is mandatory to create the alternate_stops as tasks per worker in Onfleet before calling the Nextmv API. E.g., if you have two locations that are alternate_stops and you have 5 workers, you need to create 2*5=10 tasks. You can then call the Nextmv API. Once you have the Nextmv results with the calculated routes, the unused alternate_stops need to be deleted from Onfleet. This can be done by looping over the routes and identifying which alternate_stops appear there. The alternate_stops that are not found in the routes should be removed from Onfleet and the containers can be updated.

The tasks object is composed of the following keys:

KeyDescriptionRequiredSample valueType
idsList of IDs to fetch from the Onfleet API and perform the routing.Yes[ "zntJ8QG5LPBK9mMea6zWN0lB", "cisx30t05*kQQiKYQhgyTmVF" ]array of string
paramsObject to specify the query parameters when fetching tasks.Yes{ "from": 1641963600000 }object
  • When using stop_groups, please include the list of task IDs in both the list of task ids and the list of IDs in a group inside stop_groups.
  • Please include the IDs of alternate stops in both the list of task ids and the list of alternate_stops. This is handled differently than in the original alternate stops feature, where alternate stops are only specified under the alternate_stops key but not under stops. Keep in mind that alternate_stops are specified only using task IDs, not a stop object.

The tasks params object specifies most query parameters used in the Onfleet list tasks endpoint. This endpoint is used in the backend to search for the given task ids. All the query parameters should be specified using snake_case.

The lastId query parameter is not provided, as the pagination is done automatically by the Nextmv Cloud API. Please note that there is a limit to the number of pages that are walked over. If the page limit is reached and there are tasks that haven't been found, an error will be returned in the /v0/run/run_id/status endpoint.

We recommend using the query parameters to fine-tune the search of the desired tasks. The params object is composed of the following keys:

KeyDescriptionRequiredSample valueType
fromThe starting time of the range. Tasks created or completed at or after this time will be included.Yes1641963600000int
toIf missing, defaults to the current time. The ending time of the range. Tasks created or completed before this time will be included.No1641963600000int
stateA comma-separated list of task states.No"0,1"string
workerThe ID of a worker who is currently assigned to the tasks or has previously completed the tasks.No"aWXnPY3NjKSOdisBihX8QPsL"string
complete_before_beforeThe timestamp before which the task completeBefore value must be.No1641963600000int
complete_after_afterThe timestamp after which the task completeAfter value must be.No1641963600000int
dependenciesA comma-separated list of dependency task ids. A task gets returned in the response if it has at least one of the dependencies provided.No"zntJ8QG5LPBK9mMea6zWN0lB,cisx30t05*kQQiKYQhgyTmVF"string

The workers object is composed of the following keys:

KeyDescriptionRequiredSample valueType
idsList of IDs to fetch from the Onfleet API and perform the routing.Yes[ "aWXnPY3NjKSOdisBihX8QPsL" ]array of string
paramsObject to specify the query parameters when fetching workers.No{ "states": "0,1" }object

The workers params object specifies most query parameters used in the Onfleet list workers endpoint. This endpoint is used in the backend to search for the given worker ids.

We recommend using the query parameters to fine-tune the search of the desired workers. The params object is composed of the following keys:

KeyDescriptionRequiredSample valueType
filterA comma-separated list of fields to return, if all are not desired. For example, name, location.No"name,location"string
teamsA comma-separated list of the team IDs that workers must be part of.No"aWXnPY3NjKSOdisBihX8QPsL"string
statesA comma-separated list of worker states, where 0 is off-duty, 1 is idle (on-duty, no active task) and 2 is active (on-duty, active task).No"0,1"string
phonesA comma-separated list of workers' phone numbers.No"9055555555"string

Output schema

The output schema is a JSON response that has the following keys:

KeyDescriptionType
workersList of worker objects fetched from the Onfleet API.array of object
tasksList of task objects fetched from the Onfleet API.array of object
containersList of containers specifying the final assignments. You can use this information to update the containers using the Onfleet API.array of object
solutionNexmtv Cloud output schema with solution.object
inputParsed Nexmtv Cloud input schema used to run the optimization. Showcases the transformations of tasks to stops and workers to vehiclesobject

A sample output response obtained after running the sample input is provided as a .json file.

Page last updated

Go to on-page nav menu