Creating An Array Of Email Addresses

I’m trying to loop through a list of attendees for a Google Calendar event and create an array of external attendees’ names and email addresses, before processing them. I know there’s lots of questions about constructing arrays on this forum but I couldn’t find a suitable example which showed how to do this.

I’m iterating over the attendees array -

CleanShot 2023-08-22 at 12.25.19@2x

Filtering out internal email addresses and then creating JSON objects -

Then aggregating the results into an array -

And now I have an array where the items look like this -

I thought I could simply insert that array as the body of my HTTP request, like this -

But for some reason that produces Request Content like this -

CleanShot 2023-08-22 at 12.30.03@2x

Which causes an error:

Unexpected token , in JSON at position 1

If I don’t wrap the array in square brackets, the Request Content is formatted like this -

CleanShot 2023-08-22 at 12.32.17@2x

I’ve tried making every type of change to the formatting that I can think of but I just can’t figure out how to create an array from these JSON objects?

(If there’s a more efficient way to construct this array, which uses less operations, I’d really appreciate any pointers on that too). Here’s an example of the meeting event -

[
    {
        "kind": "calendar#event",
        "etag": "\"...\"",
        "id": "...",
        "status": "confirmed",
        "htmlLink": "https://www.google.com/calendar/event?eid=...",
        "created": "2021-01-21T00:31:15.000Z",
        "updated": "2023-08-14T21:14:09.737Z",
        "summary": "...",
        "description": "..."><u>https://us02web.zoom.us/u/...</u></a>",
        "creator": {
            "email": "...@gmail.com"
        },
        "organizer": {
            "email": "...@gmail.com"
        },
        "start": "...",
        "end": "...",
        "recurrence": [
            "RRULE:FREQ=MONTHLY;UNTIL=...;BYDAY=2MO"
        ],
        "iCalUID": "...",
        "sequence": 0,
        "attendees": [
            {
                "email": "...@gmail.com",
                "responseStatus": "accepted"
            },
            {
                "email": "...@gmail.com",
                "organizer": true,
                "responseStatus": "accepted"
            },
            {
                "email": "...@gmail.com",
                "responseStatus": "declined"
            },
            {
                "email": "...@gmail.com",
                "responseStatus": "needsAction"
            },
            {
                "email": "...@gmail.com",
                "self": true,
                "responseStatus": "accepted"
            },
            {
                "email": "...@gmail.com",
                "responseStatus": "declined"
            },
            {
                "email": "...@gmail.com",
                "responseStatus": "needsAction"
            }
        ],
        "reminders": {
            "useDefault": true
        },
        "eventType": "default"
    }
]

Hi Alex,

For Request Content, you need to pass in JSON.
You can create your JSON from an array using an Iterator then Aggregate to JSON.
Right now I think you have an Iterator then Array Aggregator. So just replace your Array Aggregator with an Aggregate to JSON module and I hope that will help!

Here’s a blueprint with a short example.
contacts.json (7.6 KB)

2 Likes

Thanks a lot, I was able to remove the previous Create JSON step and create it in the Aggregate To JSON module instead -

Which produces this -

The only thing is, I’m still seeing some strange behaviour - I’m sending this data to another scenario’s webhook and rather than processing every item in the array in one go, the scenario’s processing each of them separately. Do you know why that’s happening by any chance?

I’d like to process every item in the array in a single scenario execution and respond with an array of results.

Each item in the array is being processed as a single bundle -

Are you saying your webhook is getting called once for each contact? If that’s the case it could be an Iterator doing it.

Iterator turns an array into bundles so whatever goes after an Iterator will run once for each resultant bundle, except if an Aggregator follows the Iterator, in which case the Aggregator creates one bundle.

If I’ve got this right, your Iterator should be followed by an Aggregator, then that bundle should be passed to the Webhook.

3 Likes

So I am using an Iterator, I just assumed that because the Aggregate To JSON module was an aggregator, I wouldn’t need to use an Aggregator module as well?

It looks like the aggregator is working as I expected - based on the 1 next to each module -

And the 6 bundles being transformed into 1 -

But do I still need to add an Aggregator here as well?

Edit - I’ve just tried that - aggregating the JSON - and it doesn’t seem to have any effect but maybe I used the wrong structure?

I don’t believe you want to have an Array aggregator between the Aggregate to JSON and Upsert Contacts. You’ll want to pass the result of the Aggregate to JSON directly to Upsert Contacts.

Also, it is possible the structure of Contacts may need to be updated.
It depends on how you want the data to be passed to the Webhook.

If you refer back to the blueprint I sent, you can see how the Contacts is structured.
Contacts is a collection consisting of Name/Email pairs.
image

3 Likes

Thanks for the reply.

This is what I’m doing now.

That’s how my Contacts are structured too.

I’d like to pass the Contacts to the Webhook as an array. But since when I do that, each item in the array is processed separately and the result of only one of the scenario runs is returned, I guess I’ll need to pass the array of Contacts to the Webhook as a collection, then extract the array from the collection before processing it.

I’m struggling to figure out how to add the array to a collection though toArray() doesn’t seem to work because it requires me to specify a key and values -

This ^ causes an error - “invalid array”, is there something else that I should try here?