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
svishwanathan
Helper III
Helper III

Consuming Rest APIs through Power BI

Hello Power BI Gurus


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 30 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 = Json.Document(Web.Contents("https://xxxxxx.freshservice.com/helpdesk/tickets/filter/all_tickets?format=json&page=1", [Headers=[Authorization="Basic xxxxxxxx", Content_Type="application/json"]])),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
#"Converted to Table"

 

Essentially I need to code to dynamically change the "page=" over any number of pages it may be

 

I called the function GetFresh

(page as number) as table =>
let
Source = Web.Page(Web.Contents("https://xxxxxxx.freshservice.com/helpdesk/tickets/filter/all_tickets/" , [Headers=[Authorization="Basic xxxxxxxxx", #"Content_Type"="application/json"]],
[RelativePath="?page=" & Number.ToText(page),
Query=[Headers=
[Authorization="xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
Content_Type="application/json"]]]))

in
Source

 

 

To invoke this function

 

let
Source = List.Generate( ()=>

[Result=try GetFresh(1) otherwise null, page=1],
each [Result] <> null,
each[Result=try GetFresh([page]+1) otherwise null, page=[page]+1],
each [Result])
in
Source

 

To loop through pages I created this query

 

let
Source = List.Generate( ()=>

[Result=try GetFresh(1) otherwise null, page=1],
each [Result] <> null,
each[Result=try GetFresh([page]+1) otherwise null, page=[page]+1],
each [Result])
in

Source

 

There is no syntax error on these 

 

I need help to  close this


Swati

 

 

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

@svishwanathan,

 

Web.Contents only accept two arguments.

https://community.powerbi.com/t5/Desktop/Stopping-when-looping-through-a-paginated-API-feed/m-p/3103...

Community Support Team _ Sam Zha
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

1 REPLY 1
v-chuncz-msft
Community Support
Community Support

@svishwanathan,

 

Web.Contents only accept two arguments.

https://community.powerbi.com/t5/Desktop/Stopping-when-looping-through-a-paginated-API-feed/m-p/3103...

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.