Unique True/False result for a list

Dear community,
I seamingly not been capable of doing a simple flow task.

I call an API and in return I get an list of users (id,email, etc).
Data from the flow’s webhook I would like to compare if the user is in the users list and get ONE True/False statement.

I followed this guide: 2 - Example: Are you Over 21? Working with Data Sets, Filtering, Iterating, and Evaluating. | Flows Snippets | Postman API Network

but my problem is the result handling within the IF. For each test, I get a True/False outputs depending how many users are in the API result. However I would just like to know if the user exists by email or not and then dependingly create or get the respective user.id.

Could you guide me please. I assume it is a super simple change to make…

Hi @sonic-sw

Welcome to the forums!

The simplest way to achieve this is to use the $filter function which lets you check if a list contains the desired result.

See the following example use case:

Here I have a list of records (users), I feed that list into the If Block, then select just the list of emails using list.email or whatever the field name is for you. Then I filter for values that match the email i’m looking for. I hard-coded the value but you can pass the value in as a variable as well. There is an implicit conversion to boolean in the If Block, so when the filter function returns a list of all the matching values, so long as it isn’t empty, it will be true. You can then use the “THEN” port of the if block to continue the flow in the case the user does exist, and the “ELSE” port to create the user if it doesn’t exist.

Hi @flows-daniel

thank you so much, it worked like a charm. Below the full flow in case someone is looking for it.

Maybe a pit off topic for this question, but how do I get the customers.id out of the list in case it exists. I used ycmCustomers[email=$portalCustomer] but the answer is null …? If I uses it with ycmCustomers[email=“[email protected]”], then it works.
image

Hi @sonic-sw

Unfortunately that syntax doesn’t work with variables (i’ll bring this up with the team).

The easiest way is to use a filter function again but instead of filtering just emails, filter the whole object for an email match:

This will return the whole object and you can get the customer id from that.

Greetings @flows-daniel

once more thank you for your input. For now I will be using your version.
Alternatively this also has shown to work:

image

1 Like