Rate Limits
The Samsara APIs have rate limits in place to protect our services from API traffic spikes that could put our servers at risk. If you exceed any of the rate limits described below, Samsara will respond with a 429
error code.
Ad-Hoc Rate Limit Changes
Samsara reserves the right to change rate limits for system protection. As a principle, Samsara will plan to give a heads up before any changes are made. Changes do not happen often.
Global Rate Limits
These rate limit ceilings that apply to all API endpoints. Some API endpoints have more restrictive rate limits. See Per API Rate Limits below for more details.
- Per token
- Each API access token may make 150 API requests per second
- Per organization
- Each organization may make 200 API requests per second
In other words, a single API token may only make 150 requests per second. An organization may have multiple API tokens, but an organization may only make 200 requests per second total.
Endpoint-level Rate Limits
These rate limits apply to specific endpoints within an organization. Read the description for each individual endpoint in the API Reference to see if it has an endpoint-specific rate limit. See the equipment stats endpoint as an example. Not all endpoints have rate limits documented in the API reference, so refer to the below chart for more.
Endpoint-level Rate Limit Categories
There are 5 different rate limit categories. Each endpoint falls into one of these tiers. These rate limits are applied on a per organization basis.
Category | Rate Limit |
---|---|
Level One | 100 requests per minute |
Level Two | 5 requests per second |
Level Three | 10 requests per second |
(Legacy) Tier 1 | 25 requests per second |
(Legacy) Tier 2 | 50 requests per second |
List of Rate Limits
The following Rate Limits will take effect starting October 23rd, 2023
The below are new endpoint-level rate limits. They will be rolling out starting October 23rd, 2023. For more information on how this rollout will be conducted and how it may impact you, refer to the Changelog post here. For further assistance, reach out to Samsara Support.
Endpoint | Category | Rate Limit |
---|---|---|
GET addresses | Level Two | 5 reqs/s |
POST addresses | Level One | 100 reqs/min |
DELETE addresses/.id | Level One | 100 reqs/min |
GET addresses/.id | (Legacy) Tier 1 | 25 reqs/s |
PATCH addresses/.id | Level One | 100 reqs/min |
GET attributes | Level Two | 5 reqs/s |
POST attributes | Level One | 100 reqs/min |
DELETE attributes/.id | Level One | 100 reqs/min |
GET attributes/.id | Level Two | 5 reqs/s |
PATCH attributes/.id | Level One | 100 reqs/min |
DELETE beta/fleet/driver-vehicle-assignments | Level One | 100 reqs/min |
GET beta/fleet/driver-vehicle-assignments | Level Two | 5 reqs/s |
PATCH beta/fleet/driver-vehicle-assignments | Level One | 100 reqs/min |
POST beta/fleet/driver-vehicle-assignments | Level One | 100 reqs/min |
GET beta/fleet/reports/drivers/fuel-energy | Level Two | 5 reqs/s |
GET beta/fleet/reports/vehicle/idling | (Legacy) Tier 1 | 25 reqs/s |
GET beta/fleet/reports/vehicles/fuel-energy | Level Two | 5 reqs/s |
POST beta/ifta-detail/csv | Level One | 100 reqs/min |
GET beta/ifta-detail/csv/.id | Level Two | 5 reqs/s |
GET contacts | Level Two | 5 reqs/s |
POST contacts | Level One | 100 reqs/min |
DELETE contacts/.id | Level One | 100 reqs/min |
GET contacts/.id | Level Two | 5 reqs/s |
PATCH contacts/.id | Level One | 100 reqs/min |
GET defect-types | Level Two | 5 reqs/s |
GET defects/stream | Level Two | 5 reqs/s |
GET dvirs/stream | Level Two | 5 reqs/s |
GET fleet/carrier-proposed-assignments | Level Two | 5 reqs/s |
POST fleet/carrier-proposed-assignments | Level One | 100 reqs/min |
DELETE fleet/carrier-proposed-assignments/.id | Level One | 100 reqs/min |
GET fleet/defects/history | Level Two | 5 reqs/s |
PATCH fleet/defects/.id | Level One | 100 reqs/min |
GET fleet/document-types | Level Two | 5 reqs/s |
GET fleet/documents | Level Two | 5 reqs/s |
POST fleet/documents | Level One | 100 reqs/min |
POST fleet/documents/pdfs | Level One | 100 reqs/min |
GET fleet/documents/pdfs/.id | (Legacy) Tier 1 | 25 reqs/s |
DELETE fleet/documents/.id | Level One | 100 reqs/min |
GET fleet/documents/.id | (Legacy) Tier 1 | 25 reqs/s |
DELETE fleet/driver-vehicle-assignments | Level One | 100 reqs/min |
GET fleet/driver-vehicle-assignments | Level Two | 5 reqs/s |
PATCH fleet/driver-vehicle-assignments | Level One | 100 reqs/min |
POST fleet/driver-vehicle-assignments | Level One | 100 reqs/min |
GET fleet/drivers | Level Two | 5 reqs/s |
POST fleet/drivers | Level One | 100 reqs/min |
GET fleet/drivers/efficiency | Level Two | 5 reqs/s |
GET fleet/drivers/tachograph-activity/history | Level Two | 5 reqs/s |
GET fleet/drivers/tachograph-files/history | Level Two | 5 reqs/s |
GET fleet/drivers/vehicle-assignments | (Legacy) Tier 1 | 25 reqs/s |
GET fleet/drivers/.id | (Legacy) Tier 1 | 25 reqs/s |
PATCH fleet/drivers/.id | Level One | 100 reqs/min |
POST fleet/dvirs | Level One | 100 reqs/min |
GET fleet/dvirs/history | (Legacy) Tier 2 | 50 reqs/s |
PATCH fleet/dvirs/.id | Level One | 100 reqs/min |
GET fleet/equipment | Level Two | 5 reqs/s |
GET fleet/equipment/locations | Level Two | 5 reqs/s |
GET fleet/equipment/locations/feed | Level Two | 5 reqs/s |
GET fleet/equipment/locations/history | Level Two | 5 reqs/s |
GET fleet/equipment/stats | (Legacy) Tier 1 | 25 reqs/s |
GET fleet/equipment/stats/feed | Level Three | 10 reqs/s |
GET fleet/equipment/stats/history | Level Three | 10 reqs/s |
GET fleet/equipment/.equipmentId | Level Two | 5 reqs/s |
GET fleet/hos/clocks | (Legacy) Tier 1 | 25 reqs/s |
GET fleet/hos/daily-logs | Level Two | 5 reqs/s |
GET fleet/hos/logs | Level Two | 5 reqs/s |
GET fleet/reports/drivers/fuel-energy | Level Two | 5 reqs/s |
GET fleet/reports/ifta/jurisdiction | Level Two | 5 reqs/s |
GET fleet/reports/ifta/vehicle | (Legacy) Tier 1 | 25 reqs/s |
GET fleet/reports/vehicle/idling | (Legacy) Tier 1 | 25 reqs/s |
GET fleet/reports/vehicles/fuel-energy | (Legacy) Tier 1 | 25 reqs/s |
GET fleet/routes | Level Two | 5 reqs/s |
POST fleet/routes | Level One | 100 reqs/min |
GET fleet/routes/audit-logs/feed | Level Two | 5 reqs/s |
DELETE fleet/routes/.id | Level One | 100 reqs/min |
GET fleet/routes/.id | (Legacy) Tier 1 | 25 reqs/s |
PATCH fleet/routes/.id | Level One | 100 reqs/min |
GET fleet/safety-events | (Legacy) Tier 1 | 25 reqs/s |
GET fleet/safety-events/audit-logs/feed | Level Two | 5 reqs/s |
GET fleet/settings/compliance | Level Two | 5 reqs/s |
PATCH fleet/settings/compliance | Level One | 100 reqs/min |
GET fleet/settings/driver-app | Level Two | 5 reqs/s |
PATCH fleet/settings/driver-app | Level One | 100 reqs/min |
GET fleet/settings/safety | Level Two | 5 reqs/s |
GET fleet/trailers | Level Two | 5 reqs/s |
POST fleet/trailers | Level One | 100 reqs/min |
DELETE fleet/trailers/.id | Level One | 100 reqs/min |
GET fleet/trailers/.id | Level Two | 5 reqs/s |
PATCH fleet/trailers/.id | Level One | 100 reqs/min |
GET fleet/vehicles | (Legacy) Tier 1 | 25 reqs/s |
GET fleet/vehicles/driver-assignments | Level Two | 5 reqs/s |
GET fleet/vehicles/locations | (Legacy) Tier 1 | 25 reqs/s |
GET fleet/vehicles/locations/feed | (Legacy) Tier 2 | 50 reqs/s |
GET fleet/vehicles/locations/history | (Legacy) Tier 2 | 50 reqs/s |
GET fleet/vehicles/stats | (Legacy) Tier 2 | 50 reqs/s |
GET fleet/vehicles/stats/feed | (Legacy) Tier 2 | 50 reqs/s |
GET fleet/vehicles/stats/history | (Legacy) Tier 2 | 50 reqs/s |
GET fleet/vehicles/tachograph-files/history | Level Two | 5 reqs/s |
GET fleet/vehicles/.id | (Legacy) Tier 1 | 25 reqs/s |
PATCH fleet/vehicles/.id | Level One | 100 reqs/min |
GET gateways | Level Two | 5 reqs/s |
POST gateways | Level One | 100 reqs/min |
DELETE gateways/.id | Level One | 100 reqs/min |
POST ifta-detail/csv | Level One | 100 reqs/min |
GET ifta-detail/csv/.id | Level Two | 5 reqs/s |
GET industrial/assets | Level Two | 5 reqs/s |
POST industrial/assets | Level One | 100 reqs/min |
DELETE industrial/assets/.id | Level One | 100 reqs/min |
PATCH industrial/assets/.id | Level One | 100 reqs/min |
PATCH industrial/assets/.id/data-outputs | Level One | 100 reqs/min |
GET industrial/data-inputs | Level Two | 5 reqs/s |
GET industrial/data-inputs/data-points | Level Two | 5 reqs/s |
GET industrial/data-inputs/data-points/feed | Level Two | 5 reqs/s |
GET industrial/data-inputs/data-points/history | Level Two | 5 reqs/s |
GET me | Level Two | 5 reqs/s |
POST messages | Level One | 100 reqs/min |
GET powerbi/version-check | Level Two | 5 reqs/s |
GET tags | Level Two | 5 reqs/s |
POST tags | Level One | 100 reqs/min |
DELETE tags/.id | Level One | 100 reqs/min |
GET tags/.id | Level Two | 5 reqs/s |
PATCH tags/.id | Level One | 100 reqs/min |
PUT tags/.id | Level One | 100 reqs/min |
GET user-roles | Level Two | 5 reqs/s |
GET users | Level Two | 5 reqs/s |
POST users | Level One | 100 reqs/min |
DELETE users/.id | Level One | 100 reqs/min |
GET users/.id | Level Two | 5 reqs/s |
PATCH users/.id | Level One | 100 reqs/min |
GET v1/addresses | Level Two | 5 reqs/s |
POST v1/addresses | Level One | 100 reqs/min |
DELETE v1/addresses/.address_id | Level One | 100 reqs/min |
GET v1/addresses/.address_id | (Legacy) Tier 1 | 25 reqs/s |
PATCH v1/addresses/.address_id | Level One | 100 reqs/min |
GET v1/contacts | Level Two | 5 reqs/s |
POST v1/contacts | Level One | 100 reqs/min |
DELETE v1/contacts/.contact_id | Level One | 100 reqs/min |
GET v1/contacts/.contact_id | Level Two | 5 reqs/s |
PATCH v1/contacts/.contact_id | Level One | 100 reqs/min |
POST v1/fleet/add_address | Level One | 100 reqs/min |
GET v1/fleet/assets | (Legacy) Tier 1 | 25 reqs/s |
GET v1/fleet/assets/locations | (Legacy) Tier 2 | 50 reqs/s |
GET v1/fleet/assets/reefers | (Legacy) Tier 1 | 25 reqs/s |
GET v1/fleet/assets/.assetId/locations | (Legacy) Tier 1 | 25 reqs/s |
GET v1/fleet/assets/.assetId/reefer | (Legacy) Tier 1 | 25 reqs/s |
GET v1/fleet/dispatch/routes | Level Two | 5 reqs/s |
POST v1/fleet/dispatch/routes | Level One | 100 reqs/min |
GET v1/fleet/dispatch/routes/job_updates | Level Two | 5 reqs/s |
DELETE v1/fleet/dispatch/routes/.route_external_id | Level One | 100 reqs/min |
GET v1/fleet/dispatch/routes/.route_external_id | (Legacy) Tier 1 | 25 reqs/s |
PUT v1/fleet/dispatch/routes/.route_external_id | Level One | 100 reqs/min |
GET v1/fleet/dispatch/routes/.route_external_id/history | Level Two | 5 reqs/s |
DELETE v1/fleet/dispatch/routes/.route_id | Level One | 100 reqs/min |
GET v1/fleet/dispatch/routes/.route_id | (Legacy) Tier 1 | 25 reqs/s |
PUT v1/fleet/dispatch/routes/.route_id | Level One | 100 reqs/min |
GET v1/fleet/dispatch/routes/.route_id/history | Level Two | 5 reqs/s |
GET v1/fleet/drivers | (Legacy) Tier 1 | 25 reqs/s |
POST v1/fleet/drivers | Level One | 100 reqs/min |
DELETE v1/fleet/drivers/create | Level One | 100 reqs/min |
GET v1/fleet/drivers/create | Level Two | 5 reqs/s |
PATCH v1/fleet/drivers/create | Level One | 100 reqs/min |
POST v1/fleet/drivers/create | Level One | 100 reqs/min |
GET v1/fleet/drivers/document_types | (Legacy) Tier 1 | 25 reqs/s |
GET v1/fleet/drivers/documents | Level Two | 5 reqs/s |
GET v1/fleet/drivers/inactive | Level Two | 5 reqs/s |
GET v1/fleet/drivers/inactive/.driver_id | Level Two | 5 reqs/s |
PUT v1/fleet/drivers/inactive/.driver_id | Level One | 100 reqs/min |
GET v1/fleet/drivers/inactive/.external_driver_id | Level Two | 5 reqs/s |
PUT v1/fleet/drivers/inactive/.external_driver_id | Level One | 100 reqs/min |
GET v1/fleet/drivers/summary | Level Two | 5 reqs/s |
POST v1/fleet/drivers/summary | Level One | 100 reqs/min |
DELETE v1/fleet/drivers/.driver_id | Level One | 100 reqs/min |
GET v1/fleet/drivers/.driver_id | (Legacy) Tier 1 | 25 reqs/s |
PATCH v1/fleet/drivers/.driver_id | Level One | 100 reqs/min |
POST v1/fleet/drivers/.driver_id | Level One | 100 reqs/min |
GET v1/fleet/drivers/.driver_id/dispatch/routes | (Legacy) Tier 1 | 25 reqs/s |
POST v1/fleet/drivers/.driver_id/dispatch/routes | Level One | 100 reqs/min |
POST v1/fleet/drivers/.driver_id/documents | Level One | 100 reqs/min |
DELETE v1/fleet/drivers/.driver_id/documents/.document_id | Level One | 100 reqs/min |
GET v1/fleet/drivers/.driver_id/documents/.document_id | (Legacy) Tier 1 | 25 reqs/s |
POST v1/fleet/drivers/.driver_id/hos/duty_status | Level One | 100 reqs/min |
GET v1/fleet/drivers/.driver_id/safety/score | Level Two | 5 req/s |
DELETE v1/fleet/drivers/.external_driver_id | Level One | 100 reqs/min |
GET v1/fleet/drivers/.external_driver_id | Level Two | 5 reqs/s |
PATCH v1/fleet/drivers/.external_driver_id | Level One | 100 reqs/min |
POST v1/fleet/drivers/.external_driver_id | Level One | 100 reqs/min |
GET v1/fleet/hos_authentication_logs | (Legacy) Tier 2 | 50 reqs/s |
POST v1/fleet/hos_authentication_logs | Level One | 100 reqs/min |
GET v1/fleet/hos_logs | (Legacy) Tier 1 | 25 reqs/s |
POST v1/fleet/hos_logs | (Legacy) Tier 1 | 25 reqs/s |
GET v1/fleet/hos_logs_summary | Level Two | 5 reqs/s |
POST v1/fleet/hos_logs_summary | Level One | 100 reqs/min |
GET v1/fleet/list | (Legacy) Tier 1 | 25 reqs/s |
POST v1/fleet/list | Level One | 100 reqs/min |
GET v1/fleet/locations | (Legacy) Tier 2 | 50 reqs/s |
POST v1/fleet/locations | Level One | 100 reqs/min |
GET v1/fleet/maintenance/dvirs | (Legacy) Tier 1 | 25 reqs/s |
POST v1/fleet/maintenance/dvirs | Level One | 100 reqs/min |
GET v1/fleet/maintenance/list | (Legacy) Tier 2 | 50 reqs/s |
POST v1/fleet/maintenance/list | Level One | 100 reqs/min |
GET v1/fleet/messages | Level Two | 5 reqs/s |
POST v1/fleet/messages | Level One | 100 reqs/min |
POST v1/fleet/set_data | Level One | 100 reqs/min |
GET v1/fleet/trailers/assignments | (Legacy) Tier 1 | 25 reqs/s |
GET v1/fleet/trailers/.trailerId/assignments | (Legacy) Tier 1 | 25 reqs/s |
GET v1/fleet/trips | (Legacy) Tier 2 | 50 reqs/s |
POST v1/fleet/trips | Level One | 100 reqs/min |
GET v1/fleet/vehicles/locations | Level Two | 5 reqs/s |
GET v1/fleet/vehicles/stats | Level Three | 10 reqs/s |
GET v1/fleet/vehicles/.external_vehicle_id | Level Two | 5 reqs/s |
PATCH v1/fleet/vehicles/.external_vehicle_id | Level One | 100 reqs/min |
GET v1/fleet/vehicles/.vehicle_id | (Legacy) Tier 1 | 25 reqs/s |
PATCH v1/fleet/vehicles/.vehicle_id | Level One | 100 reqs/min |
GET v1/fleet/vehicles/.vehicle_id/dispatch/routes | Level Two | 5 reqs/s |
POST v1/fleet/vehicles/.vehicle_id/dispatch/routes | Level One | 100 reqs/min |
GET v1/fleet/vehicles/.vehicle_id/locations | (Legacy) Tier 2 | 50 reqs/s |
GET v1/fleet/vehicles/.vehicle_id/safety/harsh_event | (Legacy) Tier 2 | 50 reqs/s |
GET v1/fleet/vehicles/.vehicle_id/safety/score | Level Two | 5 req/s |
POST v1/industrial/csv_imports | Level One | 100 reqs/min |
GET v1/industrial/data | Level Two | 5 reqs/s |
GET v1/industrial/data/.dataInputId | Level Two | 5 reqs/s |
GET v1/industrial/machines | Level Two | 5 reqs/s |
GET v1/industrial/machines/.machineId | Level Two | 5 reqs/s |
GET v1/industrial/machines/.machineId/form | Level Two | 5 reqs/s |
POST v1/industrial/machines/.machineId/form | Level One | 100 reqs/min |
GET v1/industrial/machines/.machineId/forms | Level Two | 5 reqs/s |
POST v1/industrial/machines/.machineId/forms | Level One | 100 reqs/min |
GET v1/industrial/mes/lines | Level Two | 5 reqs/s |
GET v1/industrial/mes/recipes | Level Two | 5 reqs/s |
GET v1/industrial/mes/runs | Level Two | 5 reqs/s |
GET v1/industrial/mes/runs/line/.external_line_id | Level Two | 5 reqs/s |
GET v1/industrial/mes/runs/line/.line_id | Level Two | 5 reqs/s |
GET v1/industrial/mes/work_orders | Level Two | 5 reqs/s |
POST v1/industrial/mes/work_orders | Level One | 100 reqs/min |
DELETE v1/industrial/mes/work_orders/.external_work_order_id | Level One | 100 reqs/min |
GET v1/industrial/mes/work_orders/.external_work_order_id | Level Two | 5 reqs/s |
PATCH v1/industrial/mes/work_orders/.external_work_order_id | Level One | 100 reqs/min |
DELETE v1/industrial/mes/work_orders/.id | Level One | 100 reqs/min |
GET v1/industrial/mes/work_orders/.id | Level Two | 5 reqs/s |
PATCH v1/industrial/mes/work_orders/.id | Level One | 100 reqs/min |
GET v1/industrial/vision/cameras | Level Two | 5 reqs/s |
GET v1/industrial/vision/cameras/.cameraId/programs | Level Two | 5 reqs/s |
GET v1/industrial/vision/run/camera/.cameraId | Level Two | 5 reqs/s |
GET v1/industrial/vision/run/camera/.cameraId/program/.programId | Level Two | 5 reqs/s |
GET v1/industrial/vision/runs | Level Two | 5 reqs/s |
GET v1/industrial/vision/runs/.cameraId | Level Two | 5 reqs/s |
GET v1/industrial/vision/runs/.cameraId/.programId/.startedAtMs | Level Two | 5 reqs/s |
POST v1/machines/history | Level One | 100 reqs/min |
POST v1/machines/list | Level One | 100 reqs/min |
GET v1/sensors/cargo | Level Two | 5 reqs/s |
POST v1/sensors/cargo | Level One | 100 reqs/min |
GET v1/sensors/door | Level Two | 5 reqs/s |
POST v1/sensors/door | Level One | 100 reqs/min |
POST v1/sensors/history | Level One | 100 reqs/min |
GET v1/sensors/humidity | Level Two | 5 reqs/s |
POST v1/sensors/humidity | Level One | 100 reqs/min |
GET v1/sensors/list | Level Two | 5 reqs/s |
POST v1/sensors/list | Level One | 100 reqs/min |
GET v1/sensors/temperature | Level Two | 5 reqs/s |
POST v1/sensors/temperature | Level One | 100 reqs/min |
GET v1/tags | Level Two | 5 reqs/s |
POST v1/tags | Level One | 100 reqs/min |
DELETE v1/tags/.tagId | Level One | 100 reqs/min |
GET v1/tags/.tagId | Level Two | 5 reqs/s |
PATCH v1/tags/.tagId | Level One | 100 reqs/min |
PUT v1/tags/.tagId | Level One | 100 reqs/min |
GET v1/user_roles | Level Two | 5 reqs/s |
GET v1/users | Level Two | 5 reqs/s |
POST v1/users | Level One | 100 reqs/min |
DELETE v1/users/.userId | Level One | 100 reqs/min |
GET v1/users/.userId | Level Two | 5 reqs/s |
PATCH v1/users/.userId | Level One | 100 reqs/min |
GET v1/versions/me | Level Two | 5 reqs/s |
GET versions/me | Level Two | 5 reqs/s |
GET v1/fleet/drivers/.driver_id/hos_daily_logs | (Legacy) Tier 1 | 25 reqs/s |
PATCH v1/fleet/drivers/.driver_id/hos_daily_logs | Level One | 100 reqs/min |
GET assets/location-and-speed/stream | Level Two | 5 reqs/s |
GET beta/address-events/history | Level Two | 5 reqs/s |
GET beta/aemp/Fleet/.pageNumber | Level Two | 5 reqs/s |
GET beta/aemp/fleet/equipment/.id | Level Two | 5 reqs/s |
GET beta/attributes | Level Two | 5 reqs/s |
POST beta/attributes | Level One | 100 reqs/min |
DELETE beta/attributes/.id | Level One | 100 reqs/min |
GET beta/attributes/.id | Level Two | 5 reqs/s |
PATCH beta/attributes/.id | Level One | 100 reqs/min |
GET beta/fleet/drivers/efficiency | Level Two | 5 reqs/s |
PATCH beta/fleet/equipment/.id | Level One | 100 reqs/min |
GET beta/fleet/hos/diagnostic-and-malfunction-events | Level Two | 5 reqs/s |
GET beta/fleet/hos/drivers/eld-events | Level Two | 5 reqs/s |
GET beta/fleet/hos/violations | Level Two | 5 reqs/s |
GET beta/fleet/trailers/stats | (Legacy) Tier 1 | 25 reqs/s |
GET beta/fleet/trailers/stats/feed | (Legacy) Tier 1 | 25 reqs/s |
GET beta/fleet/trailers/stats/history | Level Three | 10 reqs/s |
PATCH beta/fleet/vehicles/.id/immobilizer | Level One | 100 reqs/min |
GET beta/webhooks | Level Two | 5 reqs/s |
POST beta/webhooks | Level One | 100 reqs/min |
DELETE beta/webhooks/.id | Level One | 100 reqs/min |
GET beta/webhooks/.id | Level Two | 5 reqs/s |
PATCH beta/webhooks/.id | Level One | 100 reqs/min |
Handling Rate Limits
When an application hits a rate limit, the API will return an API response with a HTTP status code of 429 Too Many Requests
.
The response will include the following header:
Header | Description |
---|---|
Retry-After | Suggested time to wait before retrying (in seconds). Example: 0.40235 |
You should use the Retry-After
header in order to appropriately back-off the endpoint so that you do not get rate-limited again.
Below is a sample Python script that retrieves the current snapshot of the locations of all of your vehicles data from our API while gracefully handling rate limits. The script is designed to adhere to the API’s rate-limiting guidelines by utilizing the Retry-After
header. This ensures that the script will pause and retry the request based on the guidance, thus minimizing the chances of encountering a “429 Too Many Requests” error. Feel free to modify it to suit your specific endpoints and convenience.
import requests
import time
def make_api_request(url, headers):
while True: #Loop for retries
response = requests.get(url, headers=headers)
if response.status_code != 429: #Status other than 'Too Many Requests'
return response
#Encountered rate limit, get the time to wait from the 'Retry-After' header
retry_after = float(response.headers.get('Retry-After', 1)) #Default to 1 second if header is missing
print(f"Rate limit exceeded. Retrying in {retry_after} seconds.")
# Wait for the duration specified in 'Retry-After' before making another request
time.sleep(retry_after)
if __name__ == '__main__':
url = "https://api.samsara.com/fleet/vehicles/stats?types=gps" #Replace with the actual API endpoint
headers = {"Authorization": "Bearer YOUR_API_TOKEN"} #Replace with your actual access token
response = make_api_request(url, headers)
if response:
print(f"Successfully received data: {response.json()}")
else:
print("Failed to retrieve data.")
Updated about 1 year ago