Pagination - Data Stream - How to access the response body for pagination data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 11:15 AM - edited 10-20-2022 11:38 AM
I've got a Data Stream setup for access to an external REST API call and am having trouble getting information from the response body.
I can successfully get it load test data and to load the first page of data. I have defined the path in the Splitter step as "$.results" and it returns valid data just fine for the actual content. I'm having problem with the pagination.
The values that I need are returned in the response_body.
I've defined my pagination variables:
I've defined them all to get the next value from "Script".
When I run it as a test, I see that the response_body contains a valid entry for the page and that if I stick the response_body in a JSON formatter, is see the content as valid: there's three "header" fields and the results array.
I know that page_Response is an object and the actual response_body is a JSON formatted objec But I can't seem to get any value returned for either count or next or previous from the response body into a local variable or the variables object.
How do I specify that I want to select the response_body from the page_Response and treat is as a JSON object to be parsed, so that I can stringify item and get the page number out of it.
I suspect it's something silly, but I've looked at it everyway from Sunday.
As always, any help is very much appreciated. Scot.
Any help would be greatly appreciated.
Scot.
- Labels:
-
flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2022 10:49 AM
Ok. I've gotten part way there.
In the Rest step, I specify that the Next Value is from the "Response Body" and use the expression of $['next'] ... $['previous'] ... and $['count'] and I get back valid values for each field.
However, now if I parse out the page number and update the value, it still doesn't paginate correctly.
How to I get ServiceNow to replace the entire REST call with the entire value of the $['next'] field?
Scot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2024 01:14 PM - edited 05-22-2024 10:09 PM
Hi Scot,
I'm not positive that I'm understanding you correctly but wanted to chime in in case.
Are you setting the getNextPage variable in the Pagination Variables Script?
In the Pagination Variables Script you'll want to update the getNextPage variable to true or false based on the "next" variable from the response body. If set to true, the stream will continue and call the next page.
(Screenshot sources: The first is from the ServiceNow Developer course on Data Stream Actions. The second is from a data stream action from ServiceNow's Pluralsight Spoke.)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 12:01 PM
Hi @Scot Eagle,
Looks like the initial values for the pagination variables are missing. Drag and drop data pills from the previous step, it should work then 🙂
I hope this helps.
Have a great day 🙂