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.7K Product Ideas
- 1.7K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 292 Workbench
- 4 Cloud Amplifier
- 8 Federated
- 2.8K Transform
- 95 SQL DataFlows
- 600 Datasets
- 2.1K Magic ETL
- 3.7K Visualize
- 2.4K Charting
- 685 Beast Mode
- 43 App Studio
- 38 Variables
- 655 Automate
- 170 Apps
- 438 APIs & Domo Developer
- 42 Workflows
- 5 DomoAI
- 32 Predict
- 12 Jupyter Workspaces
- 20 R & Python Tiles
- 384 Distribute
- 110 Domo Everywhere
- 268 Scheduled Reports
- 6 Software Integrations
- 111 Manage
- 108 Governance & Security
- 8 Domo University
- 25 Product Releases
- Community Forums
- 39 Getting Started
- 29 Community Member Introductions
- 98 Community Announcements
- Domo Community Gallery
- 4.8K Archive