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();
}
Best 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();
}1
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
1 -
Got an error: "Cannot read property 'drivers' of undefined"
0 -
delete the .features from the parse
0 -
wow, just wow man
0 -
post the correct script and I'll accept it as the answer. Brilliant man
1 -
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();
}1
Categories
- All Categories
- 1.2K Product Ideas
- 1.2K Ideas Exchange
- 1.3K Connect
- 1.1K Connectors
- 273 Workbench
- 1 Cloud Amplifier
- 3 Federated
- 2.7K Transform
- 78 SQL DataFlows
- 525 Datasets
- 2.1K Magic ETL
- 2.9K Visualize
- 2.2K Charting
- 434 Beast Mode
- 22 Variables
- 510 Automate
- 114 Apps
- 388 APIs & Domo Developer
- 8 Workflows
- 26 Predict
- 10 Jupyter Workspaces
- 16 R & Python Tiles
- 332 Distribute
- 77 Domo Everywhere
- 255 Scheduled Reports
- 66 Manage
- 66 Governance & Security
- 1 Product Release Questions
- Community Forums
- 40 Getting Started
- 26 Community Member Introductions
- 68 Community Announcements
- 4.8K Archive