- Onfleet times are read as unix milliseconds and parsed to a date-time format.
- Timestamps are read as raw strings and parsed to a date-time format.
- The Onfleet integration can also be set up and edited through the Nextmv Cloud Console. See the console-configuration page for more information.
- If you have any questions or need help, please contact us at support@nextmv.io.
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>
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).
Get an existing Onfleet integration.
Get an existing Onfleet integration using the `id` associated with it.
Modify an existing Onfleet integration.
Modify an existing Onfleet integration using the `id` associated with it.
Delete an existing Onfleet integration.
Delete an existing Onfleet integration using the `id` associated with it.
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.
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.
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.
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:
- Compatible features. Onfleet's API functionality that is compatible with Nextmv Cloud API.
- Extensible features. Use Nextmv Cloud API features not supported by the Onfleet API.
Get the Nextmv and Onfleet API keys. This only needs to be done once.
Set up an Onfleet integration on Nextmv to securely store the Onfleet API key.
Create a run profile for using the Onfleet integration when requesting new runs, using the integration
id
andtype
obtained in the previous step. This only needs to be done once.Send a request to the
/v1/integrations/onfleet/run
endpoint with aJSON
body that follows the input schema to route and assign the desired tasks and workers, using the run profileid
obtained in the previous step with therun_profile
key. The API server should return arun_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.Poll the status of your run with the
/v0/run/{run_id}/status
endpoint, using therun_id
. Once the status issucceeded
, you can query your results. Please see our section on using the API for more information.Get the result of your run with the
/v0/run/{run_id}/result
endpoint, using therun_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.Update the container's tasks in the Onfleet API using the results optimized by the Nextmv Cloud routing engine.
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:
Key | Description | Required | Sample value | Type |
---|---|---|---|---|
name | Human-readable name to identify the integration key. | Yes | "Sample Onfleet integration key" | string |
description | A description of the integration. | No | "Sample Onfleet integration description" | string |
id | ID for the Onfleet integration; only lower case letters, numbers, and dashes permitted; max length 32 characters. | Yes | "onfleet-key" | string |
configuration | Object 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.
Key | Description | Required | Sample value | Type |
---|---|---|---|---|
api_key | Onfleet API key. | Yes | "<YOUR_ONFLEET_API_KEY>" | string |
compatibility | Flags 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:
Key | Description | Required | Sample value | Type |
---|---|---|---|---|
tasks | Flags to toggle on/off compatible Onfleet task attributes when parsing to a Nextmv stop. | No | { "service_time": false, "quantity": true } | object |
workers | Flags 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):Key Description Required Sample value Type complete_before_after
Parse the Onfleet task's completeBefore
andcompleteAfter
into a Nextmv stop'shard_window
.No false
boolean
dependencies
Parse the Onfleet task's dependencies
into Nextmv stop'ssucceeds
.No false
boolean
location
Parse the Onfleet task's destination.location
into the Nextmv stop'sposition
. NOTE: if you turn this toggle off (false
) you should make sure that you are specifyingposition
via task metadata, otherwise your stop will not have a location and will cause an error.No false
boolean
quantity
Parse the Onfleet task's quantity
into the Nextmv stop'squantity
.No false
boolean
service_time
Parse the Onfleet task's serviceTime
into the Nextmv stop'sstop_duration
.No false
boolean
workers
schema (you can read more about compatible Onfleet worker attributes here):Key Description Required Sample value Type active_task
Parse the Onfleet worker's activeTask
to be part of the Nextmv vehicle'sbacklog
.No false
boolean
capacity
Parse the Onfleet worker's capacity
into the Nextmv vehicle'scapacity
.No false
boolean
location
Parse the Onfleet worker's location
into the Nextmv vehicle'sstart
position.No false
boolean
tasks
Parse the Onfleet worker's tasks
to be part of the Nextmv vehicle'sbacklog
.No false
boolean
A sample schema and response are provided below:
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 attribute | Onfleet type | Onfleet example | Nextmv attribute | Nextmv type (Go) | Nextmv example |
---|---|---|---|---|---|
completeBefore , completeAfter | number | 1609522200 , 1609529400 | hard_window | [2]time.Time | [ "2021-01-01T12:30:00-00:00", "2021-01-01T14:30:00-00:00" ] |
dependencies | array string | [ "id-1", "id-2" ] | succeeds | []string | [ "id-1", "id-2" ] |
destination.location | array number | [ 1.23, 4.56 ] | position | map[string]int | { "lon": 1.23, "lat": 4.56 } |
quantity | number | 10 | quantity | int | 10 |
serviceTime | number | 5 | stop_duration | int | 300 |
quantity
can be extended to be a multi-quantity.- If the field
pickupTask
on the task is set totrue
, thequantity
will default to be negative, regardless of how it is set. - Onfleet
serviceTime
(minutes) is converted tostop_duration
(seconds), given that durations are handled in seconds inside of the Nextmv Cloud API.
Worker compatible attributes
Onfleet attribute | Onfleet type | Onfleet example | Nextmv attribute | Nextmv type (Go) | Nextmv example |
---|---|---|---|---|---|
activeTask | string | "id-1" | backlog | []string | [ "id-1" ] |
capacity | number | 100 | capacity | int | 100 |
location | array number | [ 2.294223, 48.858591 ] | start | map[string]float64 | { "lon": 2.294223, "lat": 48.858591 } |
tasks | array string | [ "id-1", "id-2" ] | backlog | []string | [ "id-1", "id-2" ] |
capacity
can be extended to be a multi-capacity.activeTask
andtasks
, if defined, are parsed to be part of thebacklog
. 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:
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
Attribute | Onfleet type | Onfleet subtype | Nextmv type (Go) | Example object |
---|---|---|---|---|
position | "object" | NA | map[string]float64 | { "name": "nextmv:0.1:position", "type": "object", "value": { "lon": 1.23, "lat": 4.56 } } |
unassigned_penalty | "number" | NA | int | { "name": "nextmv:0.1:unassigned_penalty", "type": "number", "value": 10500 } |
quantity | "object" | NA | map[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" | NA | int | { "name": "nextmv:0.1:max_wait", "type": "number", "value": 300 } |
target_time | "string" | NA | time.Time | { "name": "nextmv:0.1:target_time", "type": "string", "value": "2021-10-17T09:45:00-06:00" } |
earliness_penalty | "number" | NA | float64 | { "name": "nextmv:0.1:earliness_penalty", "type": "number", "value": 125.1 } |
lateness_penalty | "number" | NA | float64 | { "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 isint
. - 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 forprecedes
, in which case the Onfleet type is"string"
and the Nextmv type isstring
.
Worker extended attributes
Attribute | Onfleet type | Onfleet subtype | Nextmv type (Go) | Example object |
---|---|---|---|---|
start | "object" | NA | map[string]float64 | { "name": "nextmv:0.1:start", "type": "object", "value": { "lon": 2.294223, "lat": 48.858591 } } |
end | "object" | NA | map[string]float64 | { "name": "nextmv:0.1:end", "type": "object", "value": { "lon": 2.294223, "lat": 48.858591 } } |
speed | "number" | NA | float64 | { "name": "nextmv:0.1:speed", "type": "number", "value": 10.3 } |
capacity | "object" | NA | map[string]int | { "name": "nextmv:0.1:capacity", "type": "object", "value": { "volume": 4000, "weight": 6000 } } |
shift_start | "string" | NA | time.Time | { "name": "nextmv:0.1:shift_start", "type": "string", "value": "2021-10-17T09:45:00-06:00" } |
shift_end | "string" | NA | time.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" | NA | int | { "name": "nextmv:0.1:max_stops", "type": "number", "value": 10 } |
max_distance | "number" | NA | int | { "name": "nextmv:0.1:max_distance", "type": "number", "value": 1000 } |
max_duration | "number" | NA | int | { "name": "nextmv:0.1:max_duration", "type": "number", "value": 3600 } |
stop_duration_multiplier | "number" | NA | float64 | { "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" | NA | int | { "name": "nextmv:0.1:initialization_cost", "type": "number", "value": 1500 } |
- For offline workers, their
location
isnull
, so you can use thestart
attribute to define where the route should start. If the starting location is defined through metadata, it overrides the worker'slocation
attribute. - You can assign the same
start
andend
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 isint
. - 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
andshift_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:
Key | Description | Required | Type |
---|---|---|---|
routing | Options to customize the routing configurations. | Yes | object |
onfleet | Specification of tasks and workers to route. | Yes | object |
A sample input is provided as a .json
file.
Routing options
The routing options is an object that has the following keys:
Key | Description | Required | Type |
---|---|---|---|
run_profile | Object to select the run profile id you want to use. | Yes | object |
options | Select the solver options that you want to use. | No | object |
defaults | Specify the default override attributes for stops and vehicles. | No | object |
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:
Key | Description | Required | Type |
---|---|---|---|
tasks | Object to specify the tasks you want to route. | Yes | object |
workers | Object to specify the workers you want to route. | Yes | object |
stop_groups | Array to specify custom stop groups for the routes. | No | array of array of string |
alternate_stops | Array of task IDs that are considered alternate stops. | No | array of string |
duration_groups | Group of stops that add an overall service time | No | array 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 thealternate_stops
as tasks per worker in Onfleet before calling the Nextmv API. E.g., if you have two locations that arealternate_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 unusedalternate_stops
need to be deleted from Onfleet. This can be done by looping over the routes and identifying whichalternate_stops
appear there. Thealternate_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:
Key | Description | Required | Sample value | Type |
---|---|---|---|---|
ids | List of IDs to fetch from the Onfleet API and perform the routing. | Yes | [ "zntJ8QG5LPBK9mMea6zWN0lB", "cisx30t05*kQQiKYQhgyTmVF" ] | array of string |
params | Object 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 oftask
ids
and the list of IDs in a group insidestop_groups
. - Please include the IDs of alternate stops in both the list of
task
ids
and the list ofalternate_stops
. This is handled differently than in the original alternate stops feature, where alternate stops are only specified under thealternate_stops
key but not understops
. Keep in mind thatalternate_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:
Key | Description | Required | Sample value | Type |
---|---|---|---|---|
from | The starting time of the range. Tasks created or completed at or after this time will be included. | Yes | 1641963600000 | int |
to | If missing, defaults to the current time. The ending time of the range. Tasks created or completed before this time will be included. | No | 1641963600000 | int |
state | A comma-separated list of task states. | No | "0,1" | string |
worker | The ID of a worker who is currently assigned to the tasks or has previously completed the tasks. | No | "aWXnPY3NjKSOdisBihX8QPsL" | string |
complete_before_before | The timestamp before which the task completeBefore value must be. | No | 1641963600000 | int |
complete_after_after | The timestamp after which the task completeAfter value must be. | No | 1641963600000 | int |
dependencies | A 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:
Key | Description | Required | Sample value | Type |
---|---|---|---|---|
ids | List of IDs to fetch from the Onfleet API and perform the routing. | Yes | [ "aWXnPY3NjKSOdisBihX8QPsL" ] | array of string |
params | Object 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:
Key | Description | Required | Sample value | Type |
---|---|---|---|---|
filter | A comma-separated list of fields to return, if all are not desired. For example, name, location. | No | "name,location" | string |
teams | A comma-separated list of the team IDs that workers must be part of. | No | "aWXnPY3NjKSOdisBihX8QPsL" | string |
states | A 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 |
phones | A comma-separated list of workers' phone numbers. | No | "9055555555" | string |
Output schema
The output schema is a JSON
response that has the following keys:
Key | Description | Type |
---|---|---|
workers | List of worker objects fetched from the Onfleet API. | array of object |
tasks | List of task objects fetched from the Onfleet API. | array of object |
containers | List of containers specifying the final assignments. You can use this information to update the containers using the Onfleet API. | array of object |
solution | Nexmtv Cloud output schema with solution. | object |
input | Parsed Nexmtv Cloud input schema used to run the optimization. Showcases the transformations of tasks to stops and workers to vehicles | object |
A sample output response obtained after running the sample input is provided as a .json
file.