Pulling data from Array within API Call - Javascript
Hey guys,
I am working within my third party connector, I have an API that pulls contacts and their information. I need to pull emails in this but is displayed as an array and is presenting me with a blank dataset during testing.
"items": [ { "id": 0, "title": "string", "firstName": "string", "lastName": "string", "emails": [ "user@example.com" ], }
For example I have an API call that is taking that API and creating a Schema and Table.
datagrid.addColumn('id', datagrid.DATA_TYPE_DOUBLE); datagrid.addColumn('displayName', datagrid.DATA_TYPE_STRING);
datagrid.addColumn('firstName', datagrid.DATA_TYPE_STRING); // Above is the Schema and below is the Table // // process data row by row
for (var i = 0; i < table.length; i++) {
var data = table[i]; if (data.id) {
datagrid.addCell(data.id);
}
else { datagrid.addCell(null); } if (data.displayName) {
datagrid.addCell(data.displayName);
}
else { datagrid.addCell(null); }
if (data.firstName) {
datagrid.addCell(data.firstName);
}
else { datagrid.addCell(null); }
How would I add email into the above Table and Schema to pull the required information. There can be anywhere from 1 - 3 emails connected to each user within this array
Answers
-
It depends on how you want your data to be structured. You could duplicate the rows so that each email is on its own row or you'd have one record with three separate columns to store the three separate email addresses.
In either case you'd need to use a for loop and loop through the emails property of your data.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
What would be the best way to go about doing this? I would like to have each email in a new column and have tried to loop through it but ive never had to loop through an array within and array before
//maximum emails per contact is 2
for (var emailsnum = 0; emailsnum < 2; emailsnum++) {
datagrid.addColumn('contact' + '_email' + emailsnum, datagrid.DATA_TYPE_STRING);
datagrid.addColumn('contact' + '_email' + emailsnum, datagrid.DATA_TYPE_STRING);
}and
// emailAddress (set to 2 maximum)
if (data.emails) {
datagrid.addCell(data.emails);
}
else { datagrid.addCell(null); }Im not sure how to format the table for it, but should this be working?
I am still confused about looping through the Emails array within the normal dataset array0
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
- 627 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 755 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