Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

iterative macro only runs once

plshelpits2023
5 - Atom

hello

 

I am downloading json data using an api call i have built in alteryx. In the API call, i have to declare page size, which i am setting to 500, to get 500 records. then i need to add page index. for page index, i have tried iteration engine, that is, to add 1 to the page index with every iteration. However, i get only 500 records.

 

 

 

Screenshot 2023-08-01 082524.png

 

 

Screenshot 2023-08-01 082541.png

 

 

 

Screenshot 2023-08-01 082825.png

 

 

5 REPLIES 5
Felipe_Ribeir0
16 - Nebula

Hi @plshelpits2023 

 

Iterative macros are a little tricky to configure, so if possible, i personally like to avoid them. This seems to be a case where you can avoid it.

 

1-I suppose that if you make one first call to the API, it will return the total number of pages inside of the response.

 

2-Knowing the total number of pages, you can use the Generate Rows tool to generate 1 only row of url/parameters for each API call, and then the download tool can deal iteratively with each one of them.

 

Screenshot 2023-08-01 114336.png

 

Hope this is useful, debug iterative macros is boring.

 

plshelpits2023
5 - Atom

sorry, this api url does not show us total number of pages. we will do error check on response, if it errors out, then break out of iteration.

 

i can use the generate rows. the only check we will have is when items len is 0 that means no more data on remaining pages.

plshelpits2023
5 - Atom

see below. If i put 100 pageindex, it will keep checking each page to see if any data exists.

 

How can i break out of this loop when index 4, no more data exists?

 

Screenshot 2023-08-01 102931.png

plshelpits2023
5 - Atom

any help will be appreciated

Felipe_Ribeir0
16 - Nebula

Hi @plshelpits2023 

 

This problem is solved inside of this macro, and i believe that you can adapt the idea to your case: https://community.alteryx.com/t5/Community-Gallery/SurveyGizmo-Alchemer-API-GET-survey-data/ta-p/999...

 

Basically, there is a filter that see if the JSON response contains a specific value (for this case, "data."). If it do not, then we know that the macro needs to stop, and the append tool will not let the next iteration happen.

macro.png

 

 

 

 

Labels