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.
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 - //maximum emails per contact is 2
Categories
- All Categories
- 1.9K Product Ideas
- 1.9K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 306 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3K Transform
- 112 SQL DataFlows
- 649 Datasets
- 2.2K Magic ETL
- 4K Visualize
- 2.5K Charting
- 788 Beast Mode
- 78 App Studio
- 43 Variables
- 745 Automate
- 187 Apps
- 475 APIs & Domo Developer
- 67 Workflows
- 16 DomoAI
- 40 Predict
- 17 Jupyter Workspaces
- 23 R & Python Tiles
- 406 Distribute
- 117 Domo Everywhere
- 279 Scheduled Reports
- 10 Software Integrations
- 139 Manage
- 136 Governance & Security
- 8 Domo Community Gallery
- 44 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 113 Community Announcements
- 4.8K Archive