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.9K Product Ideas
- 1.9K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 303 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 104 SQL DataFlows
- 640 Datasets
- 2.2K Magic ETL
- 4K Visualize
- 2.5K Charting
- 768 Beast Mode
- 70 App Studio
- 43 Variables
- 717 Automate
- 185 Apps
- 462 APIs & Domo Developer
- 56 Workflows
- 14 DomoAI
- 39 Predict
- 16 Jupyter Workspaces
- 23 R & Python Tiles
- 402 Distribute
- 116 Domo Everywhere
- 277 Scheduled Reports
- 9 Software Integrations
- 134 Manage
- 131 Governance & Security
- 8 Domo Community Gallery
- 44 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 111 Community Announcements
- 4.8K Archive