cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TesDA
Continued Contributor
Continued Contributor

GET Restful API - Loop through offset requests

I have a Restful API request using the HTTP Step:

 

Method - Get

Authentication - Raw

Value - API key

 

It picks up everything on the first call correctly, but I dont know how to create the loop so that it continues until there are no more records.

 

Below is the JSON returned from the initial request (from the first set of records). How do I create a variable and loop through so that it uses the "next" in the JSON until "next" returns null?

 

{"count":7816,
"next":"https://blackedoutname.endpointname.com/api/v1/something/?_limit=4000&_offset=4000&include_custom_fi...",
"previous":null,
"results":[
{
"id":"9172391872397a",
"jurisdiction":{
"id":"kajhdkjhasdkjhb",
"name":"ABCDEF",
"slug":"ABCDEFno"},
"organization_person":{
"id":"kahdkjahdh",
"custom_fields":{},
"person":{
"id":"kajshdkhd",
"username":"65432","first_name":"Nate",
"last_name":"Smith",
"email":"Nate.Smith@something.com"}},
"is_primary":false,
"status":"active",
"in_compliance":false,
"start_date":"1995-01-01",
"end_date":"1996-12-31",
"extended_date":"1997-12-31",
"earned":5765.0,
"applied":5740.0,
"overall_deficit":1000.0,
"overall_applied":5740.0,
"carry_over":0.0,
"license_id":"",
"latest_annual_period":{
"id":"kasdkjahsdh",
"in_compliance":false,
"start_date":"1997-01-01",
"end_date":"1998-12-31",
"extended_date":"1999-12-31",
"earned":0.0,
"applied":0.0,
"overall_applied":0,
"overall_deficit":1000.0,
"carry_over":0.0}}]}

1 ACCEPTED SOLUTION

Accepted Solutions
TesDA
Continued Contributor
Continued Contributor

I finally figured this one out. In the returned JSON is a next, with the next http statement for the next download of json. I created a variable to pick up the "next" from the parsed JSON and then did a do until loop until next = null:

 

Step 1 - Initialize Variable

 

"next" is initially set to the initial http address.

 

Next variable.jpg

 

Step 2 - Do Until loop

 

I set the count to 4 (it was defaulted to 60), since I know the API should only need to loop 2-3 times.

 

Do Until Loop.jpg

View solution in original post

6 REPLIES 6
TesDA
Continued Contributor
Continued Contributor

Additional information added to the summary

yeamans
Advocate I
Advocate I

'm having a similar issue. I have 100s of records with a system, however I can only call 100 at a time. I need to figure out how to loop through the pages. 

 

I do get presented with s string "record": 857

 

Would i need to create a variable based upon dividing the total records by 100 then rounding up the next whole number? 

 

Flow-Fastbound.png

 

flow-fastbound-skip.png

 

 

TesDA
Continued Contributor
Continued Contributor

I finally figured this one out. In the returned JSON is a next, with the next http statement for the next download of json. I created a variable to pick up the "next" from the parsed JSON and then did a do until loop until next = null:

 

Step 1 - Initialize Variable

 

"next" is initially set to the initial http address.

 

Next variable.jpg

 

Step 2 - Do Until loop

 

I set the count to 4 (it was defaulted to 60), since I know the API should only need to loop 2-3 times.

 

Do Until Loop.jpg

Automate123
Helper III
Helper III

Hi @TesDA 

 

I have a similar issue when trying to call Jiras REST API. I am only getting back a maximum of 100 results. I am trying to apply your logic into my current flow.

 

Could you share what is inside the append to array variable connector please?

Thanks

yeamans
Advocate I
Advocate I

@Automate123,

 

Here's what I ended up doing to get it to work. 

 

 

yeamans_0-1619799287441.png

Larger Screen Shots: 

 

yeamans_1-1619799329210.png

yeamans_2-1619799467047.png

 

Condition expression is: 

length(body('Get_Items')?['items'])

 

 

yeamans_3-1619799485142.png

 

Let me know if you want help. Happy to jump on a screen share to walk through it. 

 

 

Automate123
Helper III
Helper III

Hey @yeamans 

 

Apologies for the late reply I went out and just got back.

Thank you very much for sharing your solution. From first glance it is beginning to make more sense as to how I can achieve this.

 

I am going to try and apply the logic you used into my flow now.

 

In regards to your offer of a screen share that would be much appreciated, If I struggle to get it working I will send you a DM to try and set that up with you.

 

Thanks again, I have been trying to find a solution for weeks now

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (3,289)