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.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 754 Beast Mode
- 61 App Studio
- 41 Variables
- 693 Automate
- 178 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive