Forum Discussion
FelipMark
2 years agoHelper II
Cursor based pagination in rest api query
Hi guys, I made a request to the Facebook API, which returned the data and also the next page. How do I develop code that sees the next page?
Query I'm using:
let
UrlBase = "https://graph.facebook.com/v17.0/act_636965624958777/insights",
Cabecalho = [Authorization = "Bearer TOKEN],
Parametros = [
fields = "ad_id,campaign_name,ad_name,adset_name,spend",
time_increment = "1",
level = "ad",
limit = "500"
],
Consulta = Web.Contents(
UrlBase,
[
Headers = Cabecalho,
Query = Parametros
]
),
Data = Json.Document(Consulta),
paging = Data[paging]
in
paging
result:
1 Reply
- ImkeFCommunity Champion
Hi FelipMark ,
you will find an example here: How not to miss the last page when paging with Power BI and Power Query (thebiccountant.com)applied to your scenario it could look like so:
let UrlBase = "https://graph.facebook.com/v17.0/act_636965624958777/insights", Cabecalho = [Authorization = "Bearer TOKEN], Parametros = [ fields = "ad_id,campaign_name,ad_name,adset_name,spend", time_increment = "1", level = "ad", limit = "500" ], Consulta = Web.Contents( UrlBase, [ Headers = Cabecalho, Query = Parametros ] ), paging = List.Generate( ()=> [URL = "DummyThatIsNotUsedHere", Data = Json.Document(Consulta), each [URL] <> null, each [ URL = [Data][next], Data = Web.Contents( [URL], [ Headers = Cabecalho, Query = Parametros ] ) ) in paging