Documentation Index
Fetch the complete documentation index at: https://samsara-showcase.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Recipe: Write Live Telematics Data to a CSV File
View on developers.samsara.com
Overview
The/fleet/vehicles/stats/feed endpoint allows you to sync GPS and diagnostic data. Each request will return all updates to vehicle state since the last time you made a request.
This endpoint supports querying a wide variety of vehicle stats data. See Query Parameters for details on available statistics.
This endpoint uses a cursor to keep track of the feed. Each request returns an endCursor that represents the last data point in the response. If you make another request and provide the endCursor as a query parameter, you’ll receive all the vehicle stats updates since the last request you made.
A request with no after returns the last known stats in the query.
Here’s an example sequence:
| Request | Description |
|---|---|
| Request #1 | GET /fleet/vehicles/stats/feed?types=gpsReturns last known gps data for all vehicles endCursor: abcdefg |
| Request #2 | GET /fleet/vehicles/stats/feed?types=gps&after=abcdefgReturns GPS updates since the last cursor ( abcdefg)endCursor: hijklmnop |
| Request #3 | GET /fleet/vehicles/stats/feed?types=gps&after=hijklmnopReturns GPS updates since the last cursor ( hijklmnop)endCursor: qrstuvwxyz |
| … |
engineStates as the stat type:
Request #1
The first request to/feed to kicks off the synchronization process. A cursor should not be provided in the request:
data array contains an entry for each vehicle in the fleet. In this case, there is only one vehicle, called Little Red. The engineStates array contains the last known engine state for the vehicle. In this case, the vehicle has been Off since 2020-07-03T02:11:51Z.
The pagination object contains information about the data feed. hasNextPage is false which indicates that there are no more vehicles on this page and no updates to engine state are immediately available. We should save the endCursor and use it in our next request to get updates.
Request #2
Now we want to request the updates since the last time we made a call. We provide theendCursor from the request above to the after query parameter:
On at 2020-07-05T21:48:42Z and then it turned Off at 2020-07-05T21:56:24Z. Both of these events occurred since the last time we made a request.
/feed endpoint will always return the last known stat values (even if it was from a long time ago).
Request #3
Now we make another request to get the next set of updates since our last call. Once again, you provide theendCursor from the request above to the after query parameter:
data array is empty because there have been no changes to engine state since the last request we made.
Sample Code
This sample code calls the/feed endpoint in a continuous loop to show how to use the pagination information to request vehicle stats updates. The secondsToWait variable is the number of seconds to wait between each request. You can set this value to whatever suits your use case. You should not request updates more frequently than every 5 seconds.