cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tanim
Helper I
Helper I

Iterate Over Web API Pages With Power Query

Hi everyone,

 

I need a little help, please. I have access to API data: 

 

I'm using the following code to retrieve API data:

 

let iterations = 10,
url = "https://graph.facebook.com/v2.10/[ACCOUNT ID]/insights?access_token=[ACCESS TOKEN]",

FnGetOnePage =
  (url) as record =>
   let
    Source = Json.Document(Web.Contents(url)),
    data = try Source[data] otherwise null,
    next = try Source[paging][next] otherwise null,
    res = [Data=data, Next=next]
   in
    res,

 GeneratedList =
  List.Generate(
   ()=>[i=0, res = FnGetOnePage(url)],
   each [i]<iterations and [res][Data]<>null,
   each [i=[i]+1, res = FnGetOnePage([res][Next])],
   each [res][Data])
 in
  GeneratedList

Now I'm trying to retrieve this API data: 

 

 

 

 

What changes do I need to make to the original code for this? Any help, suggestion or guidance is much appreciated!

 

Many thanks,

Tanim

1 ACCEPTED SOLUTION
Tanim
Helper I
Helper I

Fixed it by copy and pasting the last line from the new API data, it basically got rid of the extra "client_pages" bit and working like a charm. Looks like self help is the best help!

 

Fixed.png

View solution in original post

1 REPLY 1
Tanim
Helper I
Helper I

Fixed it by copy and pasting the last line from the new API data, it basically got rid of the extra "client_pages" bit and working like a charm. Looks like self help is the best help!

 

Fixed.png

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.