Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at the 2025 Microsoft Fabric Community Conference. March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for $400 discount. Register now

Reply
halll_sc
Frequent Visitor

API Loop

Good morning, have a question regarding a pipeline that I am building and looking for input on. I am making a call to an API endpoint that will only return up to 500 results. If there are more than 500 results you have to pass a page number into the body of the POST request to return the next page. I have this working right now by using a hard coded range value as the counter value in a ForEach loop. What I am trying to figure out is the best way in the ForEach loop to first check if the API doesn't return an empty JSON array and if it does break the loop and end the flow other wise conduct the CopyData activity. As a note in the API call there is no meta data return by the API to give record count or anything like that. 

My first thought was inside the ForEach loop to 1) create a WebRequest to make a call to the end point 2) create a boolean variable and if api returns result set to TRUE else FALSE. 3) if variable = TRUE process CopyData task else end the flow. 

Seems a bit unnecessary to make another API call just to see if there are results before conducting the CopyData activity. But I can't seem to think of any other way to address this. Any suggestions or feedback would be greatly appreciated. 


1 ACCEPTED SOLUTION
v-nuoc-msft
Community Support
Community Support

Hi @halll_sc 

 

You can perform the SQL query activity after the Copy Data activity. Add an sql query to calculate whether 500 records are returned.

 

How to use Script activity - Microsoft Fabric | Microsoft Learn

 

vnuocmsft_0-1730171230741.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-nuoc-msft
Community Support
Community Support

Hi @halll_sc 

 

You can perform the SQL query activity after the Copy Data activity. Add an sql query to calculate whether 500 records are returned.

 

How to use Script activity - Microsoft Fabric | Microsoft Learn

 

vnuocmsft_0-1730171230741.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

Do it the other way round.  Check if the current call has returned 500 rows. If yes, make the next call. If no, exit the loop.

Thank you for the input but the API response doesnt return a row count , so to go down that road I think I would have to perform the copy activity and get the row count of records inserted into the table and if == 500 then call the next API. Or is there another way to return the record count returned from the endpoint ? 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebFBC_Carousel

Fabric Monthly Update - February 2025

Check out the February 2025 Fabric update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.