Forum Discussion
antara_centri
2 years agoFrequent Visitor
serviceNOw Paginated API in power Query-only getting the first page data
REST API CODE IN ServiceNow (function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) { // Parse limit and page from query parameters, default to 10 and 1 if not provided ...
Anonymous
2 years agoNot applicable
Hi antara_centri ,
According to your description, each page contains the first page of records. To solve this problem, we need to adjust the getPage function to ensure that the page number query parameter is set correctly when requesting each page of data.
You can try modifying the following function
First, update the getPage function to include the page number query parameter
let
getPage = (page as number) =>
let
SourceURL = "https://watservtest.service-now.com/api/ws/test_pbi/read_dbview",
// Add the page number to the query parameters
QueryParams = [limit="10", page=Text.From(page)],
Response = Json.Document(Web.Contents(SourceURL, [Query=QueryParams])),
Result = Response[result],
Records = Result[records],
#"Converted to Table" = Table.FromList(Records, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1",
{"UniqueKey", "Ticket_Number", "Ticket_Type", "Company", "Priority", "Created_Date", "Closed",
"Ticket_Description", "Ticket_short_description", "Sla_definition", "Ticket_business_duration",
"Ticket_State", "Category", "Subcategory", "Practice_Area"},
{"Column1.UniqueKey", "Column1.Ticket_Number", "Column1.Ticket_Type", "Column1.Company",
"Column1.Priority", "Column1.Created_Date", "Column1.Closed", "Column1.Ticket_Description",
"Column1.Ticket_short_description", "Column1.Sla_definition", "Column1.Ticket_business_duration",
"Column1.Ticket_State", "Column1.Category", "Column1.Subcategory", "Column1.Practice_Area"})
in
#"Expanded Column1"
in
getPage
Then, modify the totalPages code to call this custom function and merge the data from all pages:
let
SourceURL = "https://watservtest.service-now.com/api/ws/test_pbi/read_dbview",
InitialResponse = Json.Document(Web.Contents(SourceURL, [Query=[limit="10"]])),
Result = InitialResponse[result],
TotalPages = Result[totalPages],
ListOfPages = List.Numbers(1, TotalPages),
#"Converted to Table" = Table.FromList(ListOfPages, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Invoked Custom Function" = Table.AddColumn(#"Converted to Table", "Data1", each getPage([Column1])),
CombinedData = Table.ExpandTableColumn(#"Invoked Custom Function", "Data1", {"UniqueKey", "Ticket_Number", "Ticket_Type", "Company", "Priority", "Created_Date", "Closed", "Ticket_Description", "Ticket_short_description", "Sla_definition", "Ticket_business_duration", "Ticket_State", "Category", "Subcategory", "Practice_Area"}, {"UniqueKey", "Ticket_Number", "Ticket_Type", "Company", "Priority", "Created_Date", "Closed", "Ticket_Description", "Ticket_short_description", "Sla_definition", "Ticket_business_duration", "Ticket_State", "Category", "Subcategory", "Practice_Area"})
in
CombinedData
The purpose of this code is to create a table for each page and combine the data from all pages into a single table.
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly