Samsara Telematics Integration with NextBillion.ai

In the following sections, we'll go over how to integrate Samsara Telematics with the NextBillion.ai Route Optimization API. Each step will be detailed to ensure a successful and efficient integration process, from obtaining API keys and setting up authentication to designing data pipelines and interpreting response data.

Prerequisites

Before integrating Samsara Telematics and NextBillion.ai's Route Optimization API, make sure you have the following prerequisites in place:

Samsara API Token with Read/Write Permissions

Obtain a valid API token with both read and write scopes from your Samsara account. This token will be used to gain secure access to and retrieve data from your Samsara telematics system.

API Key from NextBillion.ai

Check that you have a valid API key from NextBillion.ai. This key will be used to provide secure authentication when interacting with NextBillion.ai's services.

Samsara Asset Tracker

Ensure that the Samsara asset tracker is properly installed and configured on your drivers' vehicles. This device will transmit real-time telematics data that will be integrated with NextBillion.ai’s Route Optimization API.

By ensuring that these prerequisites are met, you will pave the way for a smooth and secure integration, allowing you to leverage the combined power of Samsara's telematics insights and NextBillion.ai's optimization capabilities for improved fleet management.

Connect and Import Data from Samsara

To effectively leverage the capabilities of both Samsara's telematics and NextBillion.ai's Route Optimization API, a seamless data integration process is required. You can unlock the power of advanced route optimization by pulling critical information from your Samsara account and orchestrating a smooth connection to the NextBillion.ai platform. This guide will walk you through the steps of pulling addresses, assets (vehicles), drivers, and addresses from Samsara and integrating them with Nextbillion.ai’s Route Optimization API.

Login to NextBillion.ai Account

Begin by logging into your NextBillion.ai account. This is your central hub for managing and accessing your API keys. API key is required to authenticate the requests made by the user.

Integrating Samsara Telematics with NextBillion.ai

To integrate Samsara Telematics with your NCC dashboard, Contact support. We will help you navigate through the process.

Pull List of Addresses

Initiate a data pull from Samsara to extract a list of addresses where your deliveries or pickups are planned. These addresses are crucial for accurate route optimization.

API Request

1
# Fetch addresses from Samsara Telematics Dashboard
2
curl --request GET \
3
--url https://api.samsara.com/addresses

API Response

1
{
2
"data": "[...]",
3
"pagination": "{...}"
4
}

Upon the successful retrieval of the address list, the frontend shall look like as the dashboard depicted below.

docs-image

Fetch Asset (Vehicle) Information

Retrieve a list of your assets, which represent your vehicles. This information will be used to optimize routes based on vehicle capacity and other parameters.

1
curl --request GET \
2
--url https://api.samsara.com/fleet/vehicles

The following image depicts the dashboard with vehicles data.

docs-image

Obtain Driver Details

Extract the data regarding your drivers, including their availability, name and other details. This ensures that route assignments align with driver capabilities.

1
curl --request GET \
2
--url https://api.samsara.com/fleet/drivers

The drivers data will look like the following dashboard upon successfull retrieval.

docs-image

The integrated dashboard will look something like this after successfully fetching all the necessary data.

docs-image

Create Jobs with Route Optimization API

Using NextBillion.ai's Route Optimization API, create optimization jobs.

POST API Request

The following API request sends data to NextBillion.ai’s Route Optimization API to create optimization jobs based on certain parameters. The response confirms the creation of jobs.

1
{
2
"request": {
3
"url": "https://api.nextbillion.io/optimization/v2?key=<your_api_key>",
4
"method": "POST",
5
"body": "{...}",
6
"headers": "{...}"
7
},
8
"response": "{...}"
9
}

Post API Response

1
{
2
"id": "2bda4ef824fa6c290e82b626ed85a8b3",
3
"message": "Optimization job created",
4
"status": "Ok"
5
}

Example JSON Response

1
{
2
"result": {
3
"code": 0,
4
"summary": "{...}",
5
6
"routes": "[...]"
7
},
8
"status": "Ok",
9
"message": ""
10
}

Integration with Route Optimization API

After successfully pulling the necessary data from Samsara, integrate the fetched data with Route Optimization using the following API endpoint.

1
GET https://api.nextbillion.io/optimization/v2/result?id={{nbaiOptimizationRun.data.id}}&key={{localStorage.values.apiKey}}

Map the fetched Samsara data to the respective API parameters. Configure optimization settings such as shift start and end time, service time, and start and end location coordinates.

1
2
btnSendSamsara.setDisabled(true);
3
let locations = [];
4
let jobs = [];
5
let shipments = [];
6
vehicles = [];
7
veh_attr = [];
8
stop_attr = [];

Trigger Route Optimization API

After successfully fetching the data to Route optimization API, trigger the API to generate optimized routes.

The following API request sends data to the NextBillion.ai server to optimize routes for vehicles using the POST method.

1
POST
2
"https://api.nextbillion.io/optimization/v2?key=<your_api_key>"
3

The following code block prepares the required data (vehicles, shipments, jobs, locations) and configuration (routing mode), then triggers the optimization process.

Note: It is required to specify the routing mode. If not specified, the API will optimize the routes for default routing mode car. The API supports truck and car as routing modes.

1
let options = {
2
routing: {
3
mode: 'car',
4
},
5
}
6
7
localStorage.setValue('vehiclesNBAI', vehicles)
8
localStorage.setValue('shipmentsNBAI', shipments)
9
localStorage.setValue('jobsNBAI', jobs)
10
localStorage.setValue('locationsNBAI', locations)
11
localStorage.setValue('nbaiOptions', options)
12
localStorage.setValue('nbaiVRPResult', null)
13
nbaiOptimizationRun.trigger()

By following these steps, you establish a robust data pipeline between Samsara's telematics and NextBillion.ai's Route Optimization API. This integration empowers you to transform your vehicle fleet management with precise and efficient route planning, dynamically adapting to real-world conditions and driving operational excellence.

© 2024 NextBillion.ai all rights reserved.