Training

Automate Training Assignments with Samsara APIs

Background

The Samsara Training Product is a software subscription solution designed to help managers assign training courses to drivers. These courses can be accessed and completed via the Samsara Driver App and Driver Portal. Currently, the process of assigning training is manual and conducted through the Training Library in the Samsara dashboard.

Samsara’s latest safety innovations, including AI-driven detections and proactive coaching tools, highlight the growing need for streamlined and scalable training solutions. By automating training assignments, customers can address safety and compliance requirements more effectively while reducing manual workload for managers.

Note: To learn more about Training, please reach out to your Samsara account representative.

Guide Overview

This guide serves as a resource for automating training assignments through API scripting. By addressing key use cases like onboarding, event-based assignments, and recurring training schedules, it provides actionable examples to help customers implement automations tailored to their needs.

Training Use Cases

This guide covers the following primary training use cases:

  • Onboarding: Assign onboarding courses when new drivers are added to your organization.
  • Event-Based: Assign courses when safety events or HOS violation events occur, based on predefined rules and thresholds.
  • Scheduling: Assign courses on a regular cadence, such as annual or quarterly training.

Deployment

To run certain automations, you will need to set up a development environment. The following are some ways you can run these automations, but you are not limited to these methods:

Scheduling on AWS

Scheduling on AWS

If the script is deployed on AWS, there are multiple ways to schedule it:

Option 1: AWS Lambda + EventBridge Scheduler (Recommended for Serverless)

AWS Lambda allows you to run the script without managing infrastructure. You can schedule it using Amazon EventBridge Scheduler. Refer to AWS Guide for more information.

Steps to Deploy and Schedule:

  1. Package the script and create an AWS Lambda function:
    1. Zip the Python script (script.py)
    2. Upload it to AWS Lambda
    3. Set the runtime to Python 3.x
  2. Define the IAM Role:
    1. Create an IAM role with the following policies:
      1. AWSLambdaBasicExecutionRole (for logging in CloudWatch)
      2. AmazonEventBridgeFullAccess (to allow EventBridge to invoke Lambda)
  3. Create an EventBridge Schedule:
    1. Open Amazon EventBridge in the AWS console
    2. Navigate to Schedules → Create schedule
    3. Choose "Invoke a Lambda function" as the target
    4. Select your Lambda function
    5. Define the schedule using a cron expression

Example Cron Expressions for Different Schedules:

FrequencyCron ExpressionDescription
Every day at 8 AM UTCcron(0 8 * ? )Runs daily at 8 AM UTC
Every Monday at 6 AM UTCcron(0 6 ? MON )Runs every Monday at 6 AM UTC
Every hourcron(0 * * ? )Runs at the start of every hour

Option 2: AWS EC2 + Cron Job (For VM-based Execution)

Refer to AWS Guide for more information. If the script runs on an EC2 instance, you can schedule it using a Linux cron job.

Steps to Deploy and Schedule:

  1. SSH into the EC2 instance: ssh -i your-key.pem ec2-user@your-instance-ip
  2. Edit the crontab file: crontab -e
  3. Add a cron job entry to schedule the script: 0 8 * * * /usr/bin/python3 /home/ec2-user/script.py >> /home/ec2-user/script.log 2>&1
    1. This runs the script every day at 8 AM UTC
    2. The output is logged to script.log
  4. Save and exit (CTRL + X, then Y, then Enter)
Scheduling on Azure

Scheduling on Azure

For Azure deployments, you can schedule the script using Azure Functions (serverless) or Azure VM + Task Scheduler (for VM-based execution).

Acure Functions + Timer Trigger (Recommended for Serverless)

Refer to Microsoft Guide for more information. Azure Functions allows running Python scripts in a serverless environment. A Timer Trigger executes the script at a specified interval.

Steps to Deploy and Schedule:

  1. Create an Azure Function App:
    1. Open Azure Portal → Create a new Function App
    2. Choose Python as the runtime
    3. Select an App Service Plan (for always-on execution) or Consumption Plan (pay-per-use)
  2. Add a Timer Trigger Function:
    1. Navigate to the Function App
    2. Click Create Function → Timer Trigger
    3. Set the cron expression
  3. Define a Schedule using CRON format:
    1. The Azure Timer Trigger uses the NCRONTAB format

Example Timer Trigger Schedules:

FrequencySchedule ExpressionDescription
Every day at 8 AM UTC0 8 * * *Runs daily at 8 AM UTC
Every Monday at 6 AM UTC0 6 * * 1Runs every Monday at 6 AM UTC
Every hour0 * * * *Runs at the start of every ho
Other Scheduling Options

Other Scheduling Options

For organizations looking for low-code or no-code automation solutions, Zapier can be a great alternative. Zapier enables you to connect Samsara APIs with other platforms without the need for extensive custom scripting.

Appendix

Additional Resources

To learn more about the Samsara Training product, refer to the website and reach out to your Samsara account representative.

Best Practices

  • Regularly review and update automation rules to ensure alignment with organizational goals
  • Validate scripts in a test environment before deployment
  • Monitor API usage to avoid exceeding rate limits