Need to connect to an API; And I'm starting from Scratch

Options

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

  • Canioagain
    Canioagain Contributor
    Answer ✓
    Options

    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: ');

     

     

     

Answers

  • Valiant
    Options

    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.

  • Canioagain
    Canioagain Contributor
    Options

    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?  

     

    domo.png

  • Canioagain
    Canioagain Contributor
    Options

    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

     

  • Valiant
    Options

    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); 

     

  • Valiant
    Options

    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.

  • Canioagain
    Canioagain Contributor
    Options

    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

     

     

    domo.png

  • Canioagain
    Canioagain Contributor
    Options

    well now we're going beyond my scope.  ugh.  

  • Canioagain
    Canioagain Contributor
    Options

    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.


     

     

     

     

  • Valiant
    Options

    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... Smiley Frustrated

     

    Oh well, at least we're not alone in the struggle!

  • Canioagain
    Canioagain Contributor
    Options

    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 sitedomo.png

  • Valiant
    Options

    Your url is invalid as it's looking for a valid {driver-id}.  Once you know a valid ID you can enter that instead.

  • Canioagain
    Canioagain Contributor
    Options

    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);

     

  • Canioagain
    Canioagain Contributor
    Options

    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

     

  • Canioagain
    Canioagain Contributor
    Answer ✓
    Options

    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: ');

     

     

     

This discussion has been closed.