04-28-2021 11:21 AM
Hello,
I am trying to call a rest get API with some pagination. The API returns the next page URL within the response, so i should be able to use this in the snap.
I am getting the value using JSON Path seen here in a mapper as an example:
I use this same JSON path in the Next URL:
Unfortunately, the snap does not call for the next page. I can only assume it sees the value as null?
Any help would be appreciated.
Many thanks
Solved! Go to Solution.
04-28-2021 01:12 PM
I believe the main issue is jsonPath is returning an array, so for Next URL you will need to index it with [0].
jsonPath($, "$entity.links[?(@.rel=='next-page')].href")[0]
And with it producing an array, a more appropriate Has next condition might be to check for the array length > 0. (Yet I suspect it will work as-is in this specific use case.)
jsonPath($, "$entity.links[?(@.rel=='next-page')].href").length > 0
07-18-2024 04:00 AM
Thank you .It did not work.I am getting only first page results.Please find the mapping for reference.
07-21-2024 09:05 PM
In my example, I did not include the root element. Please add it to the expression to make it work.
Nit: You can always use pipeline validation to build your expression.
jsonPath($, "$entity.links[?(@.rel=='next-page')].href").length > 0 ? jsonPath($, "$entity.links[?(@.rel=='next-page')].href")[0] : null