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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
all04f
Frequent Visitor

Paginate in Power Query from an API JSON file

I have been researching and digging around trying to figure out how to get pagination to work on an API dataflow in JSON file format. All of the articles and videos I have seen all tell the user to do the same thing:

  • Start from Power BI Desktop > Get data > Web page > enter the API URL

However, the way my company wants things to work is by pulling from a dataflow:

  • app.powerbi.com > Workspaces > Dataflow > Add new tables > JSON file > and then enter in the API URL

All of the videos and blog posts that I see keep referencing "total pages". I don't have a page count on the API, just about 1,200 records. How do I get it to paginate so that when I pull it in to Power BI I have more than just 200 rows?

5 REPLIES 5
all04f
Frequent Visitor

Thanks again, Pete. I am able to get the number of records where total_count=true like this:

all04f_0-1684509654164.png

 

But then I think I need to divide this totalCount by the number of results per page (which I am setting at 100). But I am not entirely sure how I do this 😞

 

No problem.

Check out this recent thread where I explained it for someone else:

https://community.powerbi.com/t5/Power-Query/How-to-deal-with-paginated-API/m-p/3222229 

 

Don't forget to be generous with the kudoes! 😉

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




BA_Pete
Super User
Super User

Hi @all04f ,

 

I think the two methods you're describing here are essentially the same thing.

As far as I know, using the JSON File connector in Dataflows just sets you up with the appropriate connection strings, there's no special wizardry happening that doesn't happen using other methods.

To get a JSON File into a Dataflow via API, just connect and transform via Desktop then open Advanced Editor, copy all the M code, open a blank Dataflow query > Advanced Editor and paste all the M code into there.

 

The 'total pages' thing IS a problem. In order to create a paginated query, you pretty much have to have this information.

I suggest going to your API documentation and finding the endpoint for this information, as it will be there somewhere.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thanks, Pete. I was able to get some sort of data flow going in Power BI Desktop, although the query just runs and runs since the Page thing is not there. The API documentation doesn't have the endpoint information for pages, so I will reach out to the vendor for assistance. 

 

Do you know if I can create this dataflow (advanced editor, blank query, M code, etc) in apps.powerbi.com? I attempted to do the exact same steps that in did in Desktop Power BI, but then I get an error that says  "Can't save dataflow. One or more tables references a dynamic data source."

 

For the dynamic data source error, you need to use relative paths.

For example:

Json.Document(
    Web.Contents(
        "https://root.url.com/",
        [
            RelativePath="relative/path.api",
            Query=
            [
                api_key=apiKey
            ]
        ]
    )
)

 

For reference, although I'm sure you've already tried, the total records value will usually be at the full endpoint URL. Using the example above, it would be at:

https://root.url.com/relative/path.api

 

...and should give you a record something like this:

BA_Pete_0-1683902430581.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors