Samsara Developer Portal

Integrate your data with the Samsara API, customize the Samsara experience, and join a community of developers building with Samsara.

Get Started

Daily Duty Status Summaries

Get a summarized report of daily duty status activity for a given driver

This guide walks you through how to get a summarized report of daily duty status activity for a given driver. Currently, the API only supports retrieving this type of summarized report on a per-driver basis.

You can request an arbitrary time range (a single day, a week, a month, etc.), and the API will return the summarized duty status activity of the driver for each day in the query.

A driver's day is determined by their Home Terminal Timezone and their ELD Day Start Hour. For example, a driver's day could be defined as midnight to midnight in the Los Angeles - PST/PDT timezone. These settings can be configured via the cloud dashboard or the API.

The recommended steps for programmatically pulling a driver's duty status summary report are:

  1. Select the driver
  2. Select the date range to query for
  3. Pull the driver's Home Terminal Timezone and ELD Day Start Hour
  4. Convert the start and end dates for the query into Unix timestamps
  5. Send the request

The following sample code defines a function that takes in a driver ID, a start date, and an end date for which to generate the duty status summary report. The driver ID is the string ID of the driver provided by Samsara. See the Drivers API for details. The start date and end date parameters are expected to be in ISO format (YYYY-MM-DD).

import requests
from datetime import date, time, datetime
from dateutil.tz import gettz
from pprint import pprint

base_url = "https://api.samsara.com"
auth_header = {"Authorization": "Bearer <<token>>"}

# Steps 1 and 2: Select driver, start and end times for query
def duty_status_summary(driver_id, start_date, end_date):
    
    # Step 3: Pull the driver's Home Terminal Timezone and ELD Day Start Hour
    driver_url = base_url + "/fleet/drivers/" + driver_id
    driver = requests.request('GET', driver_url, headers=auth_header).json()["data"]
    driver_timezone = driver["timezone"]
    if "eldDayStartHour" not in driver: # If ELD Day Start Hour is omitted, it is implied to be 0
        driver_eld_day_start_hour = 0
    else:
        driver_eld_day_start_hour = driver["eldDayStartHour"]
    
    # Step 4: Convert start and end dates into Unix timestamps in milliseconds
    # using the driver's timezone and ELD start hour
    start_ms = datetime.combine(
        date=date.fromisoformat(start_date),
        time=time(hour=driver_eld_day_start_hour),
        tzinfo=gettz(driver_timezone)
    ).timestamp()*1000
    end_ms = datetime.combine(
        date=date.fromisoformat(end_date),
        time=time(hour=driver_eld_day_start_hour),
        tzinfo=gettz(driver_timezone)
    ).timestamp()*1000

    # Send the request
    report_url = base_url + "/v1/fleet/drivers/" + driver_id + "/hos_daily_logs"
    params = {
        "start_ms": int(start_ms),
        "end_ms": int(end_ms)
    }
    response = requests.request('GET', report_url, headers=auth_header, params=params).json()
    return response

# Generate report for driver ID "1654973"
report = duty_status_summary(
    driver_id="1654973", 
    start_date="2020-07-23",
    end_date="2020-07-31")
pprint(report)

Updated 2 months ago


Daily Duty Status Summaries


Get a summarized report of daily duty status activity for a given driver

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.