Forum Discussion

luisrco's avatar
luisrco
New Member
2 years ago

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.

 

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