Need to connect to an API; And I'm starting from Scratch
Ok, our company uses something called Samsara. No connector exists in Domo. Samsara allow users to access reports via an API. They have provided me a token. Their documentation states:
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.
Do I create an Connector IDE? If so, what configuration do I use?
1. None
2. Username and Password
3. API Key
4. OAuth 2.0
And where the heck do I use this script?
https://api.samsara.com/<version>/<endpoint>?access_token={{access_token}}
Best Answer
-
Here's my final working script. Next I need to figure out how to get it to output to a table, but for now this works and hopefully will help someone else
var res = httprequest.post('https://us3.api.samsara.com/v1/fleet/drivers?access_token=xxxxxxxx','{\"groupId\": xxxx}');
DOMO.log('res: ' + res);
var data = JSON.parse(res).features;
datagrid.addColumn('id', datagrid.DATA_TYPE_STRING);
datagrid.addColumn('name', datagrid.DATA_TYPE_STRING);
DOMO.log('data: ');0
Answers
-
From what I can tell you'll want to create a custom connector using the API Key authentication option
So you'll want to start here:
https://api.domo.com/builder/index.html
Under auth use API Key, drop your key into the API Key field on the right and then you'll want to initiate a request. Here's an example I built for Quandl (a stock connector). Use the DOMO.log function to read your response. The second part is a check for validation.
var res = httprequest.get('https://www.quandl.com/api/v3/datasets/USTREASURY/YIELD?api_key=' + metadata.account.apikey)
DOMO.log('res: ' + res);
if(res.indexOf('Treasury') > 0){
auth.authenticationSuccess();
}
else{
auth.authenticationFailed('Error connecting to historical treasury data')
}The subsequent pages allow you to define reports and build out your datagrid. You should be able to follow the other examples here for that:
https://developer.domo.com/docs/custom-connectors/examples
Once done it takes a few days to be approved by Domo, but hopefully that will get you going.
Sincerely,
Valiant_Ronin
**Please mark "Accept as Solution" if this post solves your problem
**Say "Thanks" by clicking the "heart" in the post that helped you.1 -
Thank you.
It's good to know I'm on the right track. Like I stated, the documentation for Samsara says all I need is a basic authentication script. What is confusing to me is where to put it? I dropped it in, clicked run script but then get this error?0 -
I already know the query I want to post too:
https://api.samsara.com/v1/fleet/drivers/{driver_id}/hos_daily_logs
and that's all I want to do
0 -
You'll need to put your endpoint in the call script like this:
var res = httprequest.get('https://api.samsara.com/v1/fleet/drivers/{driver_id}/hos_daily_logs' + metadata.account.apikey)
DOMO.log('res: ' + res);1 -
You'll probably also need to identify a specifc driver id from the looks of that script.
I'm thinking you'll probably have to call the drivers api to get a list of driver_ids and store that in an array. You'll then need to loop through the array using your daily_logs url to build out results for multiple drivers and all of their logs.
0 -
You rock man, I'm getting closer. But I got an error...I know I have the right api token in the API Key field
0 -
well now we're going beyond my scope. ugh.
0 -
I do have a drivers qry too. I had hoped I could just pull back all the data and ETL it in Domo. Wishful thinking
https://api.samsara.com/v1/fleet/drivers
@Valiant wrote:You'll probably also need to identify a specifc driver id from the looks of that script.
I'm thinking you'll probably have to call the drivers api to get a list of driver_ids and store that in an array. You'll then need to loop through the array using your daily_logs url to build out results for multiple drivers and all of their logs.
0 -
I'm in the same boat right now actually building out an API connector for some accounting software. What I thought would be a quick data pull has turned into several hundred lines of code and counting...
Oh well, at least we're not alone in the struggle!
0 -
Any idea why it might be saying "invalid token" Pretty sure the token is right because I c&p'd the API Key from the site
0 -
Your url is invalid as it's looking for a valid {driver-id}. Once you know a valid ID you can enter that instead.
1 -
No, that's not it because I changed it to a get that doesn't require a specific ID and I still get the 'res' error
var res = httprequest.get('https://api.samsara.com/v1/fleet/drivers/inactive' + metadata.account.apikey);
DOMO.log('res: ' + res);0 -
I'm also wondering if this documentation I found is affecting the token?
$ curl -i -X POST -d "{\"groupId\": 3167}" "https://us3.api.samsara.com/v1/fleet/locations?access_token=xxxxx
0 -
Here's my final working script. Next I need to figure out how to get it to output to a table, but for now this works and hopefully will help someone else
var res = httprequest.post('https://us3.api.samsara.com/v1/fleet/drivers?access_token=xxxxxxxx','{\"groupId\": xxxx}');
DOMO.log('res: ' + res);
var data = JSON.parse(res).features;
datagrid.addColumn('id', datagrid.DATA_TYPE_STRING);
datagrid.addColumn('name', datagrid.DATA_TYPE_STRING);
DOMO.log('data: ');0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 56 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive