cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

URL Pagination, but it's buried within the string

salesopsintegra
New Contributor II

This article is very similar to my question.
Iโ€™m in a bit of a different boat though. My pagination is buried as a string within a string within the headers - not entity.
Screen Shot 2022-03-07 at 7.54.45 PM

I am able to parse with something like $headers.link.split(โ€œ;โ€)[1]
but this seems brittle.

My GET snap doesnโ€™t like this for a hasNext: $headers.link.contains(โ€˜rel=โ€œnextโ€โ€™)

1 ACCEPTED SOLUTION

del
Contributor III

Hi @salesopsintegration,

Okta is also one of my use cases, so Iโ€™ve worked this out before. Here is my approach (there are alternatives to the syntax):

image

For copy/pasteโ€ฆ
Has next:    $headers.link.contains("\"next\"")
Next URL:    $headers.link.replace(/^<(.+)>.+/,"$1")

View solution in original post

4 REPLIES 4

AleksandarAngel
Contributor III

Hi @salesopsintegration,

Can you try to replace your hasNext expression to: $headers.hasPath(โ€œlinkโ€) && $headers.link.contains(โ€œnextโ€), and try this for your nextUrl expression: $headers.link.split(โ€œ;โ€)[0].replaceAll(โ€˜<โ€™,โ€˜โ€™).replaceAll(โ€˜>โ€™,โ€˜โ€™). This should work if the link header containts only the next link, but if some cases include more than the next link, for example if there are prev and last link there would be another solution. Let me know if this helps.

Best regards,
Aleksandar.

Kanika
New Contributor

Hi @salesopsintegration,

I had the similar usecase and I used below expressions for pagination. You can also try the same.
$headers.link.contains(โ€˜rel=โ€œnextโ€โ€™) for hasNext expression and $headers.link.substr($headers.link.indexOf(โ€˜<โ€™)+1,$headers.link.indexOf(โ€˜>โ€™)-1) for nextUrl expression. Let me know if this helps.

Regards,
Kanika

del
Contributor III

Hi @salesopsintegration,

Okta is also one of my use cases, so Iโ€™ve worked this out before. Here is my approach (there are alternatives to the syntax):

image

For copy/pasteโ€ฆ
Has next:    $headers.link.contains("\"next\"")
Next URL:    $headers.link.replace(/^<(.+)>.+/,"$1")

salesopsintegra
New Contributor II

Thanks all! I knew I was on the right path - but needed some eagle eyes to point me in the right direction.