How to loop through all the keys in make.com

When I upload 3 files from the http://studio.softr.io, the make.com webhook will return “FIELD__MSRQYLUOL:0”, “FIELD__MSRQYLUOL:1” and “FIELD__MSRQYLUOL:2”, how can I loop through the key one by one in make.com, and extract all the files’ link?

the problem is I never know the exact key of name, the only thing I know is it will increase +1 everytime, if upload 5 files then the name will be FIELD__MSRQYLUOL:5

1 Like

Welcome to the Make community!

Unfortunately, if you do not know the number of fields that becomes trickier.

You can try using a Set Variable module to combine all the fields into a single array.

Those that aren’t present would be ignored. If not, you can use the remove function to remove null values.

e.g.:

{{ add(emptyarray; 2.FIELD_0; 2.FIELD_1;  2.FIELD_2;  2.FIELD_3; etc.) }}

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

1 Like

Hi @Alex15

You need to first use and array aggregator on this. Then use set variable and wrap the array output with toArray() function. Then iterate.

It will loop through all the keys.

Please download attached blueprint and adjust in your scenario.
blueprint (65).json (5.4 KB)

Regards,
Msquare Automation - Gold Partner of Make
@Msquare_Automation

1 Like

As @samliew said, it becomes tricky when you don’t know the number of keys and the key names are subject to change too.

Another solution could be to use a text parser to extract the URLs from the object. This works if you know that the value always is a URL. You can enable JSON pass-through in the Webhook:

And then use a text-parser to retrieve the URL’s from the object. This will automatically split the result in bundles:

Result:

Cheers,
Henk

5 Likes

Thank you for your great suggestion. When I tried to rebuild your solution, however, it did not work. Therefore, I slightly adapted the implementation of the Text parser.

I used “Match pattern” (Regex) instead of “Match elements” with the following pattern:

https?:\/\/[^\s"]+

The output now gives me every URL nicely separated.

Hi @Alex15
Here is a lazy method I used after I tried all these solutions and they didn’t work for me.

I had a similar issue where I wanted to iterate through several bundles containing urls returned from Airtable. Due to the nature of my automation, it is impossible to know in advance what the number of fields is, and my key names could alternate between 2 possible values.


(only one key name value is shown here)

My use case was to loop through the URLs to create a new JSON object that would contain the links and a method.
So, what I did was to use the array aggregator to convert it into a list:

Then used the Transform to JSON module to convert it to a JSON string;

Finally, I passed this JSON string to ChatGPT with a prompt to format it in my desired format. I gave it an example of the outcome, and I had to give specific instructions. For example, I asked it not to add language tags (it was adding ‘’‘json {{the JSON object}}’‘’) to the output and just return it as is.

The output:

The output has been consistent so far and I have no complaints.
One thing I would be mindful of is the token limits if your dataset is particularly large. You might want to truncate the retrieval.

Goodluck.