chansdad / samsaraapi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

samsara_api

SamsaraApi - JavaScript client for samsara_api Introduction Samsara provides API endpoints for interacting with Samsara Cloud, so that you can build powerful applications and custom solutions with sensor data. Samsara has endpoints available to track and analyze sensors, vehicles, and entire fleets. The Samsara Cloud API is a RESTful API accessed by an HTTP client such as wget or curl, or HTTP libraries of most modern programming languages including python, ruby, java. We use built-in HTTP features, like HTTP authentication and HTTP verbs, which are understood by off-the-shelf HTTP clients. We allow you to interact securely with our API from a client-side web application (though you should never expose your secret API key). JSON is returned by all API responses, including errors. If you’re familiar with what you can build with a REST API, the following API reference guide will be your go-to resource. API access to the Samsara cloud is available to all Samsara administrators. To start developing with Samsara APIs you will need to obtain your API keys to authenticate your API requests. If you have any questions you can reach out to us on support@samsara.com # Endpoints All our APIs can be accessed through HTTP requests to URLs like: curl https://api.samsara.com/<version>/<endpoint> All our APIs are versioned. If we intend to make breaking changes to an API which either changes the response format or request parameter, we will increment the version. # Authentication To authenticate your API request you will need to include your secret token. You can manage your API tokens in the Dashboard. They are visible under Settings->Organization->API Tokens. Your API tokens carry many privileges, so be sure to keep them secure. Do not share your secret API tokens in publicly accessible areas such as GitHub, client-side code, and so on. Authentication to the API is performed via HTTP Basic Auth. Provide your API token as the basic access_token value in the URL. You do not need to provide a password. curl https://api.samsara.com/<version>/<endpoint>?access_token={{access_token}} All API requests must be made over HTTPS. Calls made over plain HTTP or without authentication will fail. # Request Methods Our API endpoints use HTTP request methods to specify the desired operation to be performed. The documentation below specified request method supported by each endpoint and the resulting action. ## GET GET requests are typically used for fetching data (like data for a particular driver). ## POST POST requests are typically used for creating or updating a record (like adding new tags to the system). With that being said, a few of our POST requests can be used for fetching data (like current location data of your fleet). ## PUT PUT requests are typically used for updating an existing record (like updating devices associated with a particular tag). ## DELETE DELETE requests are used for deleting a record (like deleting a tag from the system). # Response Codes All API requests will respond with appropriate HTTP status code. Your API client should handle each response class differently. ## 2XX These are successful responses and indicate that the API request returned the expected response. ## 4XX These indicate that there was a problem with the request like a missing parameter or invalid values. Check the response for specific error details. Requests that respond with a 4XX status code, should be modified before retrying. ## 5XX These indicate server errors when the server is unreachable or is misconfigured. In this case, you should retry the API request after some delay. # Error Responses In case of a 4XX status code, the body of the response will contain information to briefly explain the error reported. To help debugging the error, you can refer to the following table for understanding the error message. | Status Code | Message | Description | |-------------|----------------|-------------------------------------------------------------------| | 401 | Invalid token | The API token is invalid and could not be authenticated. Please refer to the authentication section. | | 404 | Page not found | The API endpoint being accessed is invalid. | | 400 | Bad request | Default response for an invalid request. Please check the request to make sure it follows the format specified in the documentation. | # Versioning All our APIs are versioned. Our current API version is v1 and we are continuously working on improving it further and provide additional endpoints. If we intend to make breaking changes to an API which either changes the response format or request parameter, we will increment the version. Thus, you can use our current API version worry free. # FAQs Check out our responses to FAQs here. Don’t see an answer to your question? Reach out to us on support@samsara.com. This SDK is automatically generated by the Swagger Codegen project:

  • API version: 1.0.0
  • Package version: 1.0.0
  • Build package: io.swagger.codegen.languages.JavascriptClientCodegen

Installation

npm

To publish the library as a npm, please follow the procedure in "Publishing npm packages".

Then install it via:

npm install samsara_api --save
Local development

To use the library locally without publishing to a remote npm registry, first install the dependencies by changing into the directory containing package.json (and this README). Let's call this JAVASCRIPT_CLIENT_DIR. Then run:

npm install

Next, link it globally in npm with the following, also from JAVASCRIPT_CLIENT_DIR:

npm link

Finally, switch to the directory you want to use your samsara_api from, and run:

npm link /path/to/<JAVASCRIPT_CLIENT_DIR>

You should now be able to require('samsara_api') in javascript files from the directory you ran the last command above from.

git

If the library is hosted at a git repository, e.g. https://github.com/YOUR_USERNAME/samsara_api then install it via:

    npm install YOUR_USERNAME/samsara_api --save

For browser

The library also works in the browser environment via npm and browserify. After following the above steps with Node.js and installing browserify with npm install -g browserify, perform the following (assuming main.js is your entry file, that's to say your javascript file where you actually use this library):

browserify main.js > bundle.js

Then include bundle.js in the HTML pages.

Webpack Configuration

Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:

module: {
  rules: [
    {
      parser: {
        amd: false
      }
    }
  ]
}

Getting Started

Please follow the installation instruction and execute the following JS code:

var SamsaraApi = require('samsara_api');

var api = new SamsaraApi.AssetsApi()

var accessToken = "accessToken_example"; // {String} Samsara API access token.

var groupParam = new SamsaraApi.GroupParam(); // {GroupParam} Group ID to query.


var callback = function(error, data, response) {
  if (error) {
    console.error(error);
  } else {
    console.log('API called successfully. Returned data: ' + data);
  }
};
api.getAllAssetCurrentLocations(accessToken, groupParam, callback);

Documentation for API Endpoints

All URIs are relative to https://api.samsara.com/v1

Class Method HTTP request Description
SamsaraApi.AssetsApi getAllAssetCurrentLocations GET /fleet/assets/locations /fleet/assets/locations
SamsaraApi.AssetsApi getAllAssets GET /fleet/assets /fleet/assets
SamsaraApi.AssetsApi getAssetLocation GET /fleet/assets/{asset_id}/locations /fleet/assets/{assetId:[0-9]+}/locations
SamsaraApi.AssetsApi getAssetReefer GET /fleet/assets/{asset_id}/reefer /fleet/assets/{assetId:[0-9]+}/reefer
SamsaraApi.DefaultApi addFleetAddress POST /fleet/add_address /fleet/add_address
SamsaraApi.DefaultApi createDispatchRoute POST /fleet/dispatch/routes /fleet/dispatch/routes
SamsaraApi.DefaultApi createDriver POST /fleet/drivers/create /fleet/drivers/create
SamsaraApi.DefaultApi createDriverDispatchRoute POST /fleet/drivers/{driver_id}/dispatch/routes /fleet/drivers/{driver_id:[0-9]+}/dispatch/routes
SamsaraApi.DefaultApi createTag POST /tags /tags
SamsaraApi.DefaultApi createVehicleDispatchRoute POST /fleet/vehicles/{vehicle_id}/dispatch/routes /fleet/vehicles/{vehicle_id:[0-9]+}/dispatch/routes
SamsaraApi.DefaultApi deactivateDriver DELETE /fleet/drivers/{driver_id} /fleet/drivers/{driver_id:[0-9]+}
SamsaraApi.DefaultApi deleteDispatchRouteById DELETE /fleet/dispatch/routes/{route_id} /fleet/dispatch/routes/{route_id:[0-9]+}/
SamsaraApi.DefaultApi deleteTagById DELETE /tags/{tag_id} /tags/{tag_id:[0-9]+}
SamsaraApi.DefaultApi fetchAllDispatchRoutes GET /fleet/dispatch/routes /fleet/dispatch/routes
SamsaraApi.DefaultApi fetchAllRouteJobUpdates GET /fleet/dispatch/routes/job_updates /fleet/dispatch/routes/job_updates
SamsaraApi.DefaultApi getAllAssetCurrentLocations GET /fleet/assets/locations /fleet/assets/locations
SamsaraApi.DefaultApi getAllAssets GET /fleet/assets /fleet/assets
SamsaraApi.DefaultApi getAllDataInputs GET /industrial/data /industrial/data
SamsaraApi.DefaultApi getAllDeactivatedDrivers GET /fleet/drivers/inactive /fleet/drivers/inactive
SamsaraApi.DefaultApi getAllTags GET /tags /tags
SamsaraApi.DefaultApi getAssetLocation GET /fleet/assets/{asset_id}/locations /fleet/assets/{assetId:[0-9]+}/locations
SamsaraApi.DefaultApi getAssetReefer GET /fleet/assets/{asset_id}/reefer /fleet/assets/{assetId:[0-9]+}/reefer
SamsaraApi.DefaultApi getDataInput GET /industrial/data/{data_input_id} /industrial/data/{data_input_id:[0-9]+}
SamsaraApi.DefaultApi getDeactivatedDriverById GET /fleet/drivers/inactive/{driver_id} /fleet/drivers/inactive/{driver_id:[0-9]+}
SamsaraApi.DefaultApi getDispatchRouteById GET /fleet/dispatch/routes/{route_id} /fleet/dispatch/routes/{route_id:[0-9]+}
SamsaraApi.DefaultApi getDispatchRouteHistory GET /fleet/dispatch/routes/{route_id}/history /fleet/dispatch/routes/{route_id:[0-9]+}/history
SamsaraApi.DefaultApi getDispatchRoutesByDriverId GET /fleet/drivers/{driver_id}/dispatch/routes /fleet/drivers/{driver_id:[0-9]+}/dispatch/routes
SamsaraApi.DefaultApi getDispatchRoutesByVehicleId GET /fleet/vehicles/{vehicle_id}/dispatch/routes /fleet/vehicles/{vehicle_id:[0-9]+}/dispatch/routes
SamsaraApi.DefaultApi getDriverById GET /fleet/drivers/{driver_id} /fleet/drivers/{driver_id:[0-9]+}
SamsaraApi.DefaultApi getDvirs GET /fleet/maintenance/dvirs /fleet/maintenance/dvirs
SamsaraApi.DefaultApi getFleet POST /fleet/list /fleet/list
SamsaraApi.DefaultApi getFleetDrivers POST /fleet/drivers /fleet/drivers
SamsaraApi.DefaultApi getFleetDriversHosDailyLogs POST /fleet/drivers/{driver_id}/hos_daily_logs /fleet/drivers/{driver_id:[0-9]+}/hos_daily_logs
SamsaraApi.DefaultApi getFleetDriversSummary POST /fleet/drivers/summary /fleet/drivers/summary
SamsaraApi.DefaultApi getFleetHosAuthenticationLogs POST /fleet/hos_authentication_logs /fleet/hos_authentication_logs
SamsaraApi.DefaultApi getFleetHosLogs POST /fleet/hos_logs /fleet/hos_logs
SamsaraApi.DefaultApi getFleetHosLogsSummary POST /fleet/hos_logs_summary /fleet/hos_logs_summary
SamsaraApi.DefaultApi getFleetLocations POST /fleet/locations /fleet/locations
SamsaraApi.DefaultApi getFleetMaintenanceList POST /fleet/maintenance/list /fleet/maintenance/list
SamsaraApi.DefaultApi getFleetTrips POST /fleet/trips /fleet/trips
SamsaraApi.DefaultApi getMachines POST /machines/list /machines/list
SamsaraApi.DefaultApi getMachinesHistory POST /machines/history /machines/history
SamsaraApi.DefaultApi getSensors POST /sensors/list /sensors/list
SamsaraApi.DefaultApi getSensorsCargo POST /sensors/cargo /sensors/cargo
SamsaraApi.DefaultApi getSensorsDoor POST /sensors/door /sensors/door
SamsaraApi.DefaultApi getSensorsHistory POST /sensors/history /sensors/history
SamsaraApi.DefaultApi getSensorsHumidity POST /sensors/humidity /sensors/humidity
SamsaraApi.DefaultApi getSensorsTemperature POST /sensors/temperature /sensors/temperature
SamsaraApi.DefaultApi getTagById GET /tags/{tag_id} /tags/{tag_id:[0-9]+}
SamsaraApi.DefaultApi reactivateDriverById PUT /fleet/drivers/inactive/{driver_id} /fleet/drivers/inactive/{driver_id:[0-9]+}
SamsaraApi.DefaultApi updateDispatchRouteById PUT /fleet/dispatch/routes/{route_id} /fleet/dispatch/routes/{route_id:[0-9]+}/
SamsaraApi.DefaultApi updateTagById PUT /tags/{tag_id} /tags/{tag_id:[0-9]+}
SamsaraApi.DefaultApi updateVehicles POST /fleet/set_data /fleet/set_data
SamsaraApi.DriversApi createDriver POST /fleet/drivers/create /fleet/drivers/create
SamsaraApi.DriversApi deactivateDriver DELETE /fleet/drivers/{driver_id} /fleet/drivers/{driver_id:[0-9]+}
SamsaraApi.DriversApi getAllDeactivatedDrivers GET /fleet/drivers/inactive /fleet/drivers/inactive
SamsaraApi.DriversApi getDeactivatedDriverById GET /fleet/drivers/inactive/{driver_id} /fleet/drivers/inactive/{driver_id:[0-9]+}
SamsaraApi.DriversApi getDriverById GET /fleet/drivers/{driver_id} /fleet/drivers/{driver_id:[0-9]+}
SamsaraApi.DriversApi reactivateDriverById PUT /fleet/drivers/inactive/{driver_id} /fleet/drivers/inactive/{driver_id:[0-9]+}
SamsaraApi.FleetApi addFleetAddress POST /fleet/add_address /fleet/add_address
SamsaraApi.FleetApi createDispatchRoute POST /fleet/dispatch/routes /fleet/dispatch/routes
SamsaraApi.FleetApi createDriver POST /fleet/drivers/create /fleet/drivers/create
SamsaraApi.FleetApi createDriverDispatchRoute POST /fleet/drivers/{driver_id}/dispatch/routes /fleet/drivers/{driver_id:[0-9]+}/dispatch/routes
SamsaraApi.FleetApi createVehicleDispatchRoute POST /fleet/vehicles/{vehicle_id}/dispatch/routes /fleet/vehicles/{vehicle_id:[0-9]+}/dispatch/routes
SamsaraApi.FleetApi deactivateDriver DELETE /fleet/drivers/{driver_id} /fleet/drivers/{driver_id:[0-9]+}
SamsaraApi.FleetApi deleteDispatchRouteById DELETE /fleet/dispatch/routes/{route_id} /fleet/dispatch/routes/{route_id:[0-9]+}/
SamsaraApi.FleetApi fetchAllDispatchRoutes GET /fleet/dispatch/routes /fleet/dispatch/routes
SamsaraApi.FleetApi fetchAllRouteJobUpdates GET /fleet/dispatch/routes/job_updates /fleet/dispatch/routes/job_updates
SamsaraApi.FleetApi getAllAssetCurrentLocations GET /fleet/assets/locations /fleet/assets/locations
SamsaraApi.FleetApi getAllAssets GET /fleet/assets /fleet/assets
SamsaraApi.FleetApi getAllDeactivatedDrivers GET /fleet/drivers/inactive /fleet/drivers/inactive
SamsaraApi.FleetApi getAssetLocation GET /fleet/assets/{asset_id}/locations /fleet/assets/{assetId:[0-9]+}/locations
SamsaraApi.FleetApi getAssetReefer GET /fleet/assets/{asset_id}/reefer /fleet/assets/{assetId:[0-9]+}/reefer
SamsaraApi.FleetApi getDeactivatedDriverById GET /fleet/drivers/inactive/{driver_id} /fleet/drivers/inactive/{driver_id:[0-9]+}
SamsaraApi.FleetApi getDispatchRouteById GET /fleet/dispatch/routes/{route_id} /fleet/dispatch/routes/{route_id:[0-9]+}
SamsaraApi.FleetApi getDispatchRouteHistory GET /fleet/dispatch/routes/{route_id}/history /fleet/dispatch/routes/{route_id:[0-9]+}/history
SamsaraApi.FleetApi getDispatchRoutesByDriverId GET /fleet/drivers/{driver_id}/dispatch/routes /fleet/drivers/{driver_id:[0-9]+}/dispatch/routes
SamsaraApi.FleetApi getDispatchRoutesByVehicleId GET /fleet/vehicles/{vehicle_id}/dispatch/routes /fleet/vehicles/{vehicle_id:[0-9]+}/dispatch/routes
SamsaraApi.FleetApi getDriverById GET /fleet/drivers/{driver_id} /fleet/drivers/{driver_id:[0-9]+}
SamsaraApi.FleetApi getDvirs GET /fleet/maintenance/dvirs /fleet/maintenance/dvirs
SamsaraApi.FleetApi getFleet POST /fleet/list /fleet/list
SamsaraApi.FleetApi getFleetDrivers POST /fleet/drivers /fleet/drivers
SamsaraApi.FleetApi getFleetDriversHosDailyLogs POST /fleet/drivers/{driver_id}/hos_daily_logs /fleet/drivers/{driver_id:[0-9]+}/hos_daily_logs
SamsaraApi.FleetApi getFleetDriversSummary POST /fleet/drivers/summary /fleet/drivers/summary
SamsaraApi.FleetApi getFleetHosAuthenticationLogs POST /fleet/hos_authentication_logs /fleet/hos_authentication_logs
SamsaraApi.FleetApi getFleetHosLogs POST /fleet/hos_logs /fleet/hos_logs
SamsaraApi.FleetApi getFleetHosLogsSummary POST /fleet/hos_logs_summary /fleet/hos_logs_summary
SamsaraApi.FleetApi getFleetLocations POST /fleet/locations /fleet/locations
SamsaraApi.FleetApi getFleetMaintenanceList POST /fleet/maintenance/list /fleet/maintenance/list
SamsaraApi.FleetApi getFleetTrips POST /fleet/trips /fleet/trips
SamsaraApi.FleetApi reactivateDriverById PUT /fleet/drivers/inactive/{driver_id} /fleet/drivers/inactive/{driver_id:[0-9]+}
SamsaraApi.FleetApi updateDispatchRouteById PUT /fleet/dispatch/routes/{route_id} /fleet/dispatch/routes/{route_id:[0-9]+}/
SamsaraApi.FleetApi updateVehicles POST /fleet/set_data /fleet/set_data
SamsaraApi.IndustrialApi getAllDataInputs GET /industrial/data /industrial/data
SamsaraApi.IndustrialApi getDataInput GET /industrial/data/{data_input_id} /industrial/data/{data_input_id:[0-9]+}
SamsaraApi.IndustrialApi getMachines POST /machines/list /machines/list
SamsaraApi.IndustrialApi getMachinesHistory POST /machines/history /machines/history
SamsaraApi.RoutesApi createDispatchRoute POST /fleet/dispatch/routes /fleet/dispatch/routes
SamsaraApi.RoutesApi createDriverDispatchRoute POST /fleet/drivers/{driver_id}/dispatch/routes /fleet/drivers/{driver_id:[0-9]+}/dispatch/routes
SamsaraApi.RoutesApi createVehicleDispatchRoute POST /fleet/vehicles/{vehicle_id}/dispatch/routes /fleet/vehicles/{vehicle_id:[0-9]+}/dispatch/routes
SamsaraApi.RoutesApi deleteDispatchRouteById DELETE /fleet/dispatch/routes/{route_id} /fleet/dispatch/routes/{route_id:[0-9]+}/
SamsaraApi.RoutesApi fetchAllDispatchRoutes GET /fleet/dispatch/routes /fleet/dispatch/routes
SamsaraApi.RoutesApi fetchAllRouteJobUpdates GET /fleet/dispatch/routes/job_updates /fleet/dispatch/routes/job_updates
SamsaraApi.RoutesApi getDispatchRouteById GET /fleet/dispatch/routes/{route_id} /fleet/dispatch/routes/{route_id:[0-9]+}
SamsaraApi.RoutesApi getDispatchRouteHistory GET /fleet/dispatch/routes/{route_id}/history /fleet/dispatch/routes/{route_id:[0-9]+}/history
SamsaraApi.RoutesApi getDispatchRoutesByDriverId GET /fleet/drivers/{driver_id}/dispatch/routes /fleet/drivers/{driver_id:[0-9]+}/dispatch/routes
SamsaraApi.RoutesApi getDispatchRoutesByVehicleId GET /fleet/vehicles/{vehicle_id}/dispatch/routes /fleet/vehicles/{vehicle_id:[0-9]+}/dispatch/routes
SamsaraApi.RoutesApi updateDispatchRouteById PUT /fleet/dispatch/routes/{route_id} /fleet/dispatch/routes/{route_id:[0-9]+}/
SamsaraApi.SensorsApi getSensors POST /sensors/list /sensors/list
SamsaraApi.SensorsApi getSensorsCargo POST /sensors/cargo /sensors/cargo
SamsaraApi.SensorsApi getSensorsDoor POST /sensors/door /sensors/door
SamsaraApi.SensorsApi getSensorsHistory POST /sensors/history /sensors/history
SamsaraApi.SensorsApi getSensorsHumidity POST /sensors/humidity /sensors/humidity
SamsaraApi.SensorsApi getSensorsTemperature POST /sensors/temperature /sensors/temperature

Documentation for Models

Documentation for Authorization

All endpoints do not require authorization.

About


Languages

Language:JavaScript 99.9%Language:Shell 0.1%