Build a single bullet list (for email) by accessing all arrays from matching keys

I’ve got one that’s been giving me a headache and would love some fresh eyes.

For context: I am storing users in a Firebase Firestore db. Each user document has an associated “brands” array containing strings, which are the brands that the user wants email notifications for.

Every day a JSON object is received via webhook containing new media related to each brand and I am building this scenario to send a single email to each user that contains just the updates on the brands that particular user cares about.

I’m receiving json data via webhook with the following structure:

Here is the user data coming from Firestore

So in the above example, there were media updates from the ELITE brand and CAVALLO brand.

Our user (only one in the db right now) cares about both of those, so ideally the output html for the email would be something like:

UPDATES:

ELITE:

  • ELITE/the-vortek-wheel-for-testing.png
  • ELITE/the-other-vortek-wheel-for-testing.png

CAVALLO:

  • CAVALLO/the-vortek-wheel-for-testing.png
  • CAVALLO/the-other-vortek-wheel-for-testing.png

Here’s the end of the scenario

For a final bit of clarity, if the user brand array only listed ELITE, then the email sent out should only contain the links from ELITE.

I’ve successfully used a filter to loop through the user “brands” array and only pass through to the next module if the array contains a matching key in the webhook data, but beyond that I’m lost.

Welcome to the Make community!

Hello, could you please provide the output bundles for the modules shown in your screenshots?

Please provide the input and output bundles of the modules by running the scenario (or get from the scenario History tab), then click the white speech bubble on the top-right of each module and select “Download input/output bundles”.
Screenshot_2023-10-06_141025

A.

Save each bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.

Uploading them here will look like this:

module-1-input-bundle.txt (12.3 KB)
module-1-output-bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted bundles in this manner:

  • Either add three backticks ``` before and after the code, like this:

    ```
    input/output bundle content goes here
    ```

  • Or use the format code button in the editor:
    Screenshot_2023-10-02_191027

Providing the input/output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

This will allow others to better assist you. Thanks!

2 Likes

@samliew thanks for chiming in.

The output bundle from the receiving webhook:

[
    {
        "ELITE": [
            "EliteLink1",
            "EliteLink2"
        ]
    },
    {
        "CAVALLO": [
            "CavalloLink1",
            "CavalloLink2"
        ]
    }
]

The output bundle from Firestore:

[
    {
        "fields": {
            "brands": [
                "ELITE",
                "CAVALLO",
                "AZARA"
            ],
            "email": "fakeemailhere@gmail.com"
        }
    }
]

This structure is problematic, since it’s a named key in a collection.

We’ll need to flatten it first to combine them into something like this

{ "data": [
    {
        "key": "ELITE",
        "value": [
            "EliteLink1",
            "EliteLink2"
        ]
    },
    {
        "key": "CAVALLO",
        "value": [
            "CavalloLink1",
            "CavalloLink2"
        ]
    }
]}

3 Likes

I’ve got that working now, thank you.

Any thoughts on how to construct the relevant headings and link lists for each email?

Here’s the updated JSON structure

Here’s my filter to match only when the user “brands” array matches the brand from the JSON:

Then I have an iterator because…I don’t know why :joy:

After WAY TOO MUCH time spent on this, I finally got it working. Enjoy the visual of my monstrous scenario. :joy:

3 Likes

Hi @gaegeroot :wave:

Awesome work getting this up an running with the assistance of @samliew :clap: It’s great that you did not give up, pushed through, and can now bask in the glory of this beauty of a scenario!

Thanks a lot for keeping us in the loop on your progress and for sharing the final setup with us! :pray:

1 Like