For each from an array in the previous response

Options

Hi,

Just been off of XANO (Was in XANOAX mode 😁) for a couple of months, and oh boy forgot a lot of stuff, feeling rusty.

Hope you can help me:

I am running an API request and I get an array "results". I now need to run a For each loop to each id inside the results. but when I try to get the path I get the 1 value in the array:

api_2.response.result.results.0.protocol_id

api_2.response.result.results.1.protocol_id

How can I set the path, so that it will go through the whole array and not a certain index position of the id?

Thank you very much in advance.

Best Answer

  • JJ
    JJ Member ✭
    Answer βœ“
    Options

    Ok I solved it, was simpler than as I remembered, Just grab the "item" in the Loop and then in the body of the loop I used "item.protocol_id".

    It worked as expected 😊. Thanks anyway @Lefteris - blupry.com πŸ™‚.

Answers

  • Lefteris - blupry.com
    Lefteris - blupry.com Member ✭✭
    Options

    Hey @JJ ,

    Welcome back!

    If I understood correctly, all you need to do is iterate through the list "api_2.response.result.results" and each time save the item.protocol_id (maybe by pushing it into an array created outside the loop)

  • JJ
    JJ Member ✭
    Options

    Hi @Lefteris - blupry.com ,

    Happy to be back, thanks 😎.

    Each time I will go iterate through the list correct, but I will use that id of the list to make another API request based on the ID.

    Example:

    I run an "Accounts" API request, it gives me as a result, an array list of account details which "protocol_id" is the primary key for each account.

    Then I need to use a For each loop, to iterate through each "protocol_id", in order to get all "Contacts" from each account.

    I am going through the videos again, but didn't find a solution yet "out of the box". Thank you very much.