I'm having a problem building a workflow.
I make a first request which returns 49 elements in JSON form.
For each of these elements, I want to make another API request.
The first request works fine, but I can't build a loop that takes the values from request 1. I've tried using JS code and the 'Loop' block but I can't find the right solution.
It looks like you're almost there but you need to change a couple of the references in the Loop block to get this processing properly.
First (and I think likely the main reason you are having an issue), is that in the loop block each item in the query1.data object will be referenced as value anywhere you want to use that currently iterated item.
For example, in your GET URL setup you are showing {{query1.data.components.myKey}} -- this is going to need to changed to {{value.components.myKey}}
Second, I see in the example above that you are trying to reference the property myKey however your second screenshot does not show any objects containing this property. Should this be value.components.key?
Finally, to test to make sure that these values are returning properly you can use a loop block with a JS Code setup and see the values returned with something like:
let myKey = value.components.key
let qualifier = value.components.qualifier
console.log(myKey)
console.log(qualifier)
...
return value
Another thing that you can use in a loop block (like the keyword value) is index which will give you the current loop index being processed.
Yes, you're right, it's 'key' and not 'myKey'. It was just to explain but it seems to be confusing.
I tried to add value as you said but it is not working. There is nothing after value.
When I run the first module, the API returns an object and when I run the whole workflow, the logs return an error starting from request 2, as you can see in the image. I've tried parsing the JSON but it still doesn't work.
Oh, I see now. So what you need to do is gather the components property which has all of the sub elements listed as an array. In this case, since query1 is returning an object with the data you need you will just need to gently mold the data into the right iterable form.
The simplest way to do this would be to insert a JS Code node before query2 which just returns the components property like this:
return query1.data.components
Then, you use that node as the input for the loop node and instead of {{value.components...}} you would just be accessing the properties of each component via {{value.key}} or {{value.qualifier}}
If you are only running the full workflow you may not see any properties autofill on the value keyword but if you step through each node to generate outputs on the canvas when you get to the loop block value should show the first entry in your array as a sample/default.