I'm asking my database for email addresses in different fields, here's a sample response:
{ "data": [ { "1358": { "value": "me@me.com" }, "1505": { "value": "you@you.com" }, "2047": { "value": "they@they.com" }, "2050": { "value": "" } } ], "metadata": { "numFields": 4, "numRecords": 1, "skip": 0, "totalRecords": 1 }}
I use those emails in an outgoing API call to Nylas to send emails. The Nylas /send endpoint takes an array in the request body for recipient emails:
"to":[ { "email": "me@me.com" }, { "email": "you@you.com" }, { "email": "they@they.com" } ]
That is my desire result, that if a field returns a blank value in the initial response that it doesn't get included in the final list. The API call to Nylas will fail if the "email" key is blank.
In OutSystems the recipient email or "to" attribute is a custom list structure with two text attributes, Email and Name. What do I have to do after I get that response with the email values to create a parameter that I can use in the outgoing API request to Nylas?
Hello Daniel,
The first thing I would do is create a structure with the list/object format that the target API expects:
And in your action, create a list of this structure:
Then you can follow this example:
Filter from the database only records that actually have email (email <> "") , and pass this list from the base to the structure list that will be sent to the API:
If you still have questions or if I haven't expressed myself in the right way, feel free to reply.
Hope it helps.
Regards.
Thanks for the response @Agno Silveira , as is usually the case I seemed to have left out some key background information. My database is Quickbase, it's not an OutSystems hosted database, so I need to call Quickbase with an API call, and the response is comes back in a structured list.
From the Analyst1Email, Analyst2Email, Analyst3Email and Analyst4Email I need to make the "to" list. And if one of those is blank, it needs to be omitted from the list.
Are their structure (Analyst1Email, Analyst2Email, Analyst3Email and Analyst4Email) the same?
Can you expand and upload a new image please, and also an image of the structure of the API that will send the mailing list "to".
Their structures are all the same:
This is the end of the process sending the outgoing API call to Nylas:
Can you share your .OML ? So I see what the best option to indicate you.
I can't do that, sorry.
In general, if I am getting data back from an API, how can I turn that data into a list?
You must create a variable of type list of a structure in your action, this structure is created by you according to the example below.
After that, assign the return value of your API to the list structure.
If possible, separate an example from your .oml and share it, then I'll return the adjusted .oml with a more practical example.
But the API returns more than just the email values, and its structure doesn't match my ToNylas structure. I need a way to say, just take these 4 values from the API and turn them into a ToNylas list. How can I do that?
Even if your input (GET) and output (POST) data are different, you can pass the value from one to the other through assign, indicating which field will receive each value:
Note that you need to create a local variable of the type your ToNylas endpoint expects. Here's how it looks in the POST:
Each input and output has its particularities in terms of structure and variables, so if you can get an .oml with your example, it would be better for us to validate.
Or use list append.
But in my example my "GetPerson" is a "GetProject" and it's not returning a list of different emails, it's just returning different values from different fields. How do I say, make a list where item 1 is taken from the value of field 1358, then, if field field 1505 doesn't have blank data, make it a new item in the list, otherwise skip, then, if field field 2047 doesn't have blank data, make it a new item in the list, otherwise skip, then, if field field 2050 doesn't have blank data, make it a new item in the list, otherwise skip.