Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
FelipMark
Helper II
Helper 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:

FelipMark_0-1694635736682.png

 



1 REPLY 1
ImkeF
Community Champion
Community 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

 

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors