Building a Connector: Now trying to get output from my script

Let me start off by saying I'm a novice.  And also by saying that Domo Support and there documentation is disappointing when it comes to helping you output data when building a connector.  The combination of the two have induced a headache.
I am building a connector.

I am able to access an API.  

I am able to get data to populate the console.

I am not able to create an output dataset that I can send over to Domo.

 

Here is my script that returns data to the console, but that's as far as I can get.  I would really appreciate any assistance I can get.  

 

var res = httprequest.post('https://us3.api.samsara.com/v1/fleet/drivers?access_token=xxxxxx','{\"groupId\": ssss}');

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

for(var i = 0; i < data.length; i++){

var drivers = data[i].properties;

datagrid.addCell(id);
datagrid.addCell(name);

datagrid.endRow();

}

domo.png

Tagged:

Best Answer

  • Valiant
    Valiant Coach
    Answer ✓

    Glad it worked for you. Here you go:

     

    var res = httprequest.post('https://us3.api.samsara.com/v1/fleet/drivers?access_token=xxxxxx','{\"groupId\": ssss}');

    //DOMO.log('res: ' + res);


    //added .drivers to read further into the JSON file before parsing
    var data = JSON.parse(res).drivers;

    datagrid.addColumn('id', datagrid.DATA_TYPE_STRING);
    datagrid.addColumn('name', datagrid.DATA_TYPE_STRING);

    //lets you read data
    DOMO.log('data: ' + data);

    for(var i = 0; i < data.length; i++){

    var drivers = data[i].properties;

    datagrid.addCell(data[i].id);
    datagrid.addCell(data[i].name);

    datagrid.endRow();

    }

     

Answers

  • You're very close.

     

    It's helpful to use the Domo.log to see what part of the array you're accessing when reading the JSON file.

     

    Here's a quick tweak:

    var res = httprequest.post('https://us3.api.samsara.com/v1/fleet/drivers?access_token=xxxxxx','{\"groupId\": ssss}');

    //DOMO.log('res: ' + res);


    //added .drivers to read further into the JSON file before parsing
    var data = JSON.parse(res).features.drivers;

    datagrid.addColumn('id', datagrid.DATA_TYPE_STRING);
    datagrid.addColumn('name', datagrid.DATA_TYPE_STRING);

    //lets you read data
    DOMO.log('data: ' + data);

    for(var i = 0; i < data.length; i++){

    var drivers = data[i].properties;

    datagrid.addCell(data[i].id);
    datagrid.addCell(data[i].name);

    datagrid.endRow();

    }

    I updated your JSON parse to read further into the file and return the interior of drivers.

     

    I also modified the Domo.log to return the results of this new parse by showing the result of the data variable.

     

    I'll need to see that before I can give too much more detail. But the last part of your addCell I also tweaked in a guess as to what will return ID and name. 

     

    Sincerely,

    Valiant

  • Got an error:  "Cannot read property 'drivers' of undefined"


  • delete the .features from the parse

  • wow, just wow man

     

    domo.png

  • post the correct script and I'll accept it as the answer.  Brilliant man

  • Valiant
    Valiant Coach
    Answer ✓

    Glad it worked for you. Here you go:

     

    var res = httprequest.post('https://us3.api.samsara.com/v1/fleet/drivers?access_token=xxxxxx','{\"groupId\": ssss}');

    //DOMO.log('res: ' + res);


    //added .drivers to read further into the JSON file before parsing
    var data = JSON.parse(res).drivers;

    datagrid.addColumn('id', datagrid.DATA_TYPE_STRING);
    datagrid.addColumn('name', datagrid.DATA_TYPE_STRING);

    //lets you read data
    DOMO.log('data: ' + data);

    for(var i = 0; i < data.length; i++){

    var drivers = data[i].properties;

    datagrid.addCell(data[i].id);
    datagrid.addCell(data[i].name);

    datagrid.endRow();

    }

     

This discussion has been closed.