Using pagination for Okta API

I am attempting to use n8n to query the Okta API and having trouble with pagination via the HTTP Request node.

Okta’s API returns the next page URL in the $response.headers.link as a string type with both the self and next links embedded

https://example.okta.com/api/v1/users?limit=200; rel=“self”, https://example.okta.com/api/v1/users?after=200uai9nhfsweDMx731t7&limit=200; rel=“next”

I’m not sure how using a fixed value or javascript expression i can convert this output form the API into the “next” URL since it’s not standalone string or an array i can reference. Seems like perhaps some complex regex to extract the contexts maybe? I just feel there has to be a better way

Hey @Dan_Westness,

Welcome to the community :cake:

Best I can think of without playing with the API would be to use some regex to get the next url.

I ended up with this as a working model. I feel like it might be a little dirty as my regex-fu is novice.

image

2 Likes

Hey @Dan_Westness,

That looks like what I would do, Maybe we should change it to automatically extract the next if it exists :thinking:

1 Like