Track Route Progress

You can poll for route stop state changes using this REST API endpoint:

GET https://api.samsara.com/fleet/routes/audit-logs/feed

See the full reference docs here .

You can read more about stop state changes in the Route Tracking Knowledge Base article.

This endpoint is designed for you to repeatedly poll using an endCursor to get updates since the last time you sent a request. For example:

Call SequenceDescription
Call #1GET /fleet/routes/audit-logs/feed
Returns all job updates within the last 24 hours plus
endCursor: abcdefg
Call #2GET /fleet/routes/audit-logs/feed?after=abcdefg
Returns all job updates since the last time you called the endpoint plus
endCursor: hijklmnop
Call #3GET /fleet/routes/audit-logs/feed?after=hijklmnop
Returns all job updates since the last time you called the endpoint plus
endCursor: qrstuvwuxyz
...

You can repeatedly poll the endpoint as described above and get new updates each time.

An example response to the GET /fleet/routes/audit-logs/feed with one update (the data array could contain many updates) looks like:

{
    "data": [
        {
            "time": "2021-05-06T11:24:21.887Z",
            "type": "route tracking",
            "source": "automatic",
            "operation": "stop en route",
            "route": {
                "id": "4319641111",
                "name": "Route 1234"
            },
            "changes": {
                "before": {
                    "stops": [
                        {
                            "id": "4439719125",
                            "state": "scheduled"
                        }
                    ]
                },
                "after": {
                    "stops": [
                        {
                            "id": "4439719125",
                            "enRouteTime": "2021-05-06T11:23:40.746Z",
                            "state": "en route"
                        }
                    ]
                }
            }
        }
    ],
    "pagination": {
        "endCursor": "3e71bf73-eb3a-4ee5-a997-6a2c4c98b7fa",
        "hasNextPage": false
    }
}

You can write a loop to repeatedly poll the endpoint to get new updates:

import requests
import json
import time

url = "https://api.samsara.com/fleet/routes/audit-logs/feed"
headers = {"Authorization": "Bearer <token>"}
params = {}

while True:
    response = requests.request("GET", url, headers=headers, params=params).json()
    for update in response["data"]:
        # Do something with stop update
        pass
    params["after"] = response["pagination"]["endCursor"]
    if response["pagination"]["hasNextPage"] == False:
      time.sleep(5)