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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
luisrco
New Member

API paging via token in the request body.

Hi all,

I am an average Power BI user and a novice in Power Query coding.

I'm trying to get data to make a report from this API integration Query cases - Cases (torq.io).

The data I obtain is divided into multiple pages. The paging method is based on a next_page_token provided by the previous request and must be entered in JSON format in the body of the next POST request.

 

I am able to get the first page but so far I have not been able to bring me the rest of the pages.

luisrco_0-1716483212657.png

 

Here the code that I'm trying:

 

 

 

let
    Url             = "https://api.torq.io/public/v1alpha/cases/query",
    Token           = "vvvvvvvvvv-wwwwwwwwww-xxxxxxxxxxx-yyyyyyyyyyy-zzzzzzzzzzz",
    initial_body           ="{
                        ""filters"": {
                        ""created_at"" : {
                        ""relative"" : ""RELATIVE_LAST_12_HOURS""
                        }
                        },
                        ""order"" : ""dsc"",
                        ""order_by"" : ""created_at"",
                        ""page_size"" : 500
                        }",



    body_json       = Json.Document (initial_body),
    Options         = [Headers = [
                    Authorization = "Bearer " & Token,
                    #"Content-Type"="application/json",
                    #"Accept"="application/json"
                ],
            Content = Json.FromValue(body_json)
            ],
    RawData = Web.Contents (Url,Options),


InitialWebCall = Json.Document(RawData),
datalist = List.Generate(() => InitialWebCall,
                            each List.Count([next_page_token]) <> null,
                            each try Json.Document(Web.Contents(
                                Url,
                                [
                                Headers = [Authorization = "Bearer " & Token, #"Content-Type"="application/json",#"Accept"="application/json"],
                                {
                                    "page_token" : HOW CAN GET PREVIOUS TOKEN PAGINATION??
                                }
                                ])) 
                            otherwise [next_page_token = {}], each [next_page_token]),      
in
datalist

 

 

 

I don't know how to put the paging token from the previous query into the body of the new query in JSON format.

Any suggestions?

Thank you very much in advance.

1 REPLY 1
Anonymous
Not applicable

Hi @luisrco 

Based on your description, you can refer to the following link, it describes how to implement pagination in power query.

How To Do Pagination In Power Query | by Mark Tiedemann | Medium

And you can refer to the following similar thread

Solved: Pagination with Rest API query and JSON file - Microsoft Fabric Community

 

 

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Solution Authors
Top Kudoed Authors