cancel
Showing results for 
Search instead for 
Did you mean: 

Pagination from JSON Path Has Next URL - Trustpilot

Tommy
New Contributor III

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.

image

I am getting the value using JSON Path seen here in a mapper as an example:
image

I use this same JSON path in the Next URL:
image

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

1 ACCEPTED SOLUTION

del
Contributor III

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

View solution in original post

6 REPLIES 6

del
Contributor III

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

Tommy
New Contributor III

Amazing. Thanks Del that worked perfectly. I’ve marked as resolved,

VijayKasindala
New Contributor

Hi ,

I have given jsonPath($, "$.[*].links[?(@.rel=='next-page')].href")[0] in 'Next URL'.

It is not working.can you please provide your inputs?

Output JSON :

[
{
"links":
[
{
"href":
"https://api.trustpilot.com/v1/private/business-units/abc"
"method":
"GET"
"rel":
"next-page"
}
{
"href":
"https://api.trustpilot.com/v1/business-units/abc"
"method":
"GET"
"rel":
"business-units"
}
]
}
]

svatada
Former Employee

You will get an IndexOutOfBoundsException if the entity does not include next-page information.

update your exp to below:

jsonPath($, "$.links[?(@.rel=='next-page')].href").length > 0 ? jsonPath($, "$.links[?(@.rel=='next-page')].href")[0] : null