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.7K Product Ideas
- 1.7K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 292 Workbench
- 4 Cloud Amplifier
- 8 Federated
- 2.8K Transform
- 95 SQL DataFlows
- 602 Datasets
- 2.1K Magic ETL
- 3.7K Visualize
- 2.4K Charting
- 695 Beast Mode
- 43 App Studio
- 39 Variables
- 658 Automate
- 170 Apps
- 441 APIs & Domo Developer
- 42 Workflows
- 5 DomoAI
- 32 Predict
- 12 Jupyter Workspaces
- 20 R & Python Tiles
- 386 Distribute
- 111 Domo Everywhere
- 269 Scheduled Reports
- 6 Software Integrations
- 113 Manage
- 110 Governance & Security
- 8 Domo University
- 30 Product Releases
- Community Forums
- 39 Getting Started
- 29 Community Member Introductions
- 98 Community Announcements
- Domo Community Gallery
- 4.8K Archive