Data Stream: Can't access next value From Response body if array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 01:23 PM
Hi everyone,
I'm trying to use the Pagination Setup step, but I'm having trouble with the "Next value from: Response Body" and the pageResponse.
In my case, I receive a JSON from a REST call (from outside SN) that has this format:
{
"name": "blablabla",
"description": "bipbip",
"elements": [
{
"value_a": "zja",
"value_b": "uvuxdjcl",
"links": [
{
"rel": "self",
"href": "https://..."
}
]
},
{
"value_a": "zja ",
"value_b": "uvuxdjcl",
"links": [
{
"rel": "self",
"href": "https://..."
}
]
},
{
"value_a": "zja",
"value_b": "uvuxdjcl",
"links": [
{
"rel": "self",
"href": "https://..."
}
]
}
],
"links": [
{
"rel": "self",
"href": "https://...?%24start_index=0&%24count=5"
},
{
"rel": "prev",
"title": "Previous interval",
"href": "?%24count=5"
},
{
"rel": "next",
"title": "Next interval",
"href": "?%24start_index=5&%24count=5"
}
]
}
We do not have access to "X-Total-Count" in the response header, so I need to either find how many items were created from the previous REST call, or the length of Elements in the body of the previous call, or if there is a "next" link.
I use $.elements in the splitter step, the outputs created are valid and complete, so I know that it exist and has data (plus I see it in the Execution details), same for Links.
That being said, when I try to use
I can easily access variables.description, it gives me the right description, but variables.elementsBody is an empty string.
Parsing variables.elementsBody gives me "Error: Empty JSON string, Detail: empty JSON string"
If I try to use the object I get that it's undefined. But I know for a fact that elements is there, and not empty.
I get the same result for $.links .
So the strings values in the JSON are accessible, but not the arrays?
When I try to access pageResponse I get :
{"item_count":"","error_message":null,"item":"","response_headers":{"Strict-Transport-Security":["max-age=15768000 ; includeSubDomains ; preload"],"Cache-Control":["max-age=0, no-cache, no-store"],"Connection":["keep-alive"],"Expires":["Tue, 21 May 2024 18:50:33 GMT"],"Pragma":["no-cache"],"Content-Length":["2674"],"Content-Language":["en"],"Date":["Tue, 21 May 2024 18:50:33 GMT"],"Content-Type":["application/json;subtype=...;charset=UTF-8"]},"status_code":200,"count":"","ds_count":"","error_code":0,"page_count":""}
So the item_count is always "" even if 5 items were created on the last call, and I do not have access to the respon se_body.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 01:03 PM - edited 05-24-2024 01:50 PM
I've tried a lot of the same things as you and have had very similar experiences with not being able to access the full response body directly via the Pagination Variables nor the Pagination Variables Script. I'm not sure this is possible even though it mentions accessing response_body through the pageResponse variable in the ServiceNow docs. It would kind of make sense that ServiceNow wouldn't allow access to the full response body in each page iteration I suppose though but I'd still be super curious if someone else has had success with this.
What about accessing the "next" links object in a JSONPath Expression and then passing that to the Pagination Variable Script?
I imagine on the final page that is called, the title or href value for that object might be empty? Or something that signifies there isn't a next page?
If you so you could try something like this:
Where you pass the href key value of the "next" links object to the Pagination Variables script. And then can use that to determine if getNextPage should be true or false.
The above JSONPath Expression - $["links"][2].["href"] or $.links[2].href - does rely on the "next" object always being at the 2nd index of the links array though. If this isn't the case you could potentially still grab this in another way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 04:31 PM - edited 10-03-2024 04:34 PM
Did you ever find a solution to this, as I'm having the same issue?
This seems to be a fundamental design flaw in the Data Stream design. Where SN believes every endpoint always has a pagination variable of some type, when clearly some do not. The fact we do not have access to the actual response body payload in the pageResponse variable and not even access to the past URL that was sent to the endpoint basically makes this step and these Flow action Data Sources for some integrations, not possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 07:31 AM
Hello,
I did not find a solution to this issue.
It does seem to be a major flaw, not having access to the response body payload was a real problem.
I ended up making a first call to get the Count value of the table and passed this value as a flow variable. Like that I know how many item to retrive and can evaluate how many pages I'll need.
We were lucky that this API was there and working, because otherwise we would not have been able to complete this integration.
Good luck on your side.