Hello everyone,
I am also very new here and trial and error myself through.
Right now I got stuck in one scenario where I need an metadata-element of the Json of a HTTP Request to do the next call in a loop until the “after” - metadata-element is empty.
I tried to do the loop via IF, Set or Code Nodes to but always stumbled over the fact that I need an empty string parameter for next_page_id in the first call instead of a set Variable or a [not found] which I get, when the looping nodes were not executed yet. And then the “metadata”-“after” result as an input in the subsequent loops.
Please help me finding an elegant solution to this.
Hi @ourHDC, it seems the service from your screenshot requires authenticated requests so I can’t test this one myself.
I need an empty string parameter for next_page_id in the first call instead of a set Variable
This part should be doable though even without access to your API. You can use the conditional/ternary operator to check whether a value is available. If so, use it and if not use an empty string instead.
Here’s a quick example workflow:
The exact expression I have used here is {{ $json.page ? $json.page + 1 : '' }}. If $json.page is truthy I’ll use that value and add 1 to it (which is how the dummy API I have used here works), otherwise I am simply returning am empty string.
In your case the cursor might be nested a little deeper so you might also need optional chaining here (essentially using ?. instead of just . to access your fields) in order to avoid hitting an error.
I suspect the error on your latest screenshot could be related to nodes inside the loop being executed on their own. Can you confirm which error you are getting when executing the workflow instead of a single node?