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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Looping API (total results not available)

Hi,

 

Been asking a similar question before, but for a different API.

 

The current API gives me the ID of the last row much like this example from hubspot API

 

https://api.hubapi.com/crm/v3/objects/contacts?limit=10&archived=false&hapikey=demo

 

For the demonstrations sake i have set the limit to 10 row just to visualize how an "incomplete" call will look like

 

wes2015_0-1633640785625.png

As you can see the two last columns is for the paging. It gives the last row ID in the "after" column and the full link of the next 10 rows in the "link" column.

 

 

wes2015_1-1633640933196.png

If i set the limit to 100, all 33 rows in the Demo dataset is returned. As you can see, the "after" and "link" columns are not returned.

 

As mentioned, I have solved a similar issue before, but that API gave me the total number of rows available in the paging, enabling use of the List.Generate() way to do it by creating a loop table of [total number of results available] / [limit in each call] = number of calls.

 

How do I proceed with this when i don't know how many times to loop the call?

 

Thanks in advance

Wes

 

 

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

Please see this video for another way to approach this.  If you API support offset or skip in your web call, you can leverage that after value and dynamically generate a list of numbers with the right spacing for the right number of calls.

Power BI - Tales From The Front - REST APIs - YouTube

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Thanks @mahoneypat , your video was perfect for the previous API I was working with where I got the total number of rows available.

 

In the current API the pagination part of the call return only gives me the following.

 

wes2015_0-1633677135803.png

 

after: the ID of the last result in the current call

link: full link of the next call, skipping all rows in the current call (&after=32401)

 

Also worth mentioning, the ID is not sequential. The next ID might be 33551, i.e. its not 32402.

 

Any hints?

 

Wes

If you know approximately how many to expect, you could make a list of numbers to use as your "after" values that intentionally goes just past it and then remove any rows where you get error instead of "Table".  That would be simpler than a recursive solution.

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Nice video @mahoneypat.

That's an elegant way to handle API calls.

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.