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
TinoC
Frequent Visitor

Consuming Rest APIs through Power BI and Paginate

This is my first attempting at consuming Rest APIs through power query. After much struggle, i am able to make an API call successfully. It returns only 80 records. The documentation says that I have to append page number at the end of the query string to succesfully paginate.

 

Something like this:

 

let
Source = Web.Page(Web.Contents("https://" , [Headers=[Authorization="Token XXXXXXXXXX", #"Content_Type"="application/json"]],
[RelativePath="?page=" & Number.ToText(page),
Query=[Headers=
[Authorization="xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
Content_Type="application/json"]]]))

in

Source

 

Essentially I need to code to dynamically change the "page=" over any number of pages it may be. Could you please help me to complete the code

3 REPLIES 3
TinoC
Frequent Visitor

I got this code but I can't get it to work:

 

let
Source = Web.Page(Web.Contents("https://" , [Headers=[Authorization="Token xxxxx"#"Content_Type"="application/json"]],
[RelativePath="?page=" & Number.ToText(page),
Query=[Headers=
[Authorization="xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
Content_Type="application/json"]]]))


in
Source

= List.Generate
() => [Page Number=0, Func=null],
each [Page Number] = 1 or Table.RowCount([Func]) > 1,
each [Page Number=_[Page Number]+1,
Func=GetData([Page Number]+1)],
each _[Func])
TinoC
Frequent Visitor

Thanks for your answer Mark, now it generates the following error:

 

Expression.Error: 3 arguments were passed to a function which expects between 1 and 2.
Details:
Pattern=
Arguments=[List]

 

screen1.pngscreen2.png

mahoneypat
Employee
Employee

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.  Not sure why you need Web.Page and Web.Contents.  Usually just Web.Contents is needed.

 

let
    Source = List.Numbers(1, 10,1),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "PageNumber"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "WebContents", each Web.Page(Web.Contents("https://" , [Headers=[Authorization="Token XXXXXXXXXX", #"Content_Type"="application/json"]],
[RelativePath="?page=" & [PageNumber],
Query=[Headers=
[Authorization="xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
Content_Type="application/json"]]])))
in
    #"Added Custom"

 

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


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.