Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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:
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
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 9 | |
| 8 | |
| 7 | |
| 6 |