According to the docs (Pagination), pagination should be performed using the “link” header in the response.
However, when requesting all users (/api/v1/users) from a SPA using a fetch CORS request, the “links” header can not be accessed from the headers object:
@Lijia Thanks for the reply! Unfortunately, I cannot access the link property of the response header in JavaScript on the client. So do I have to manually build the “after” URL for the next page and see if the response is an empty array or is there a better way to find out if I still have to fetch more users?
@andrea No, I’m using the Authorization code with PKCE flow to get an access token which is then stored in the session storage on the client. The request to /users is then authorized by adding the access token to the request header.
Hm… I’m also having trouble getting the “link” header back when making a Fetch request to /users with an access token, but I can clearly see it in the network events in the browser. I’m checking to see if this is expected or not.
@andrea Thanks for trying it out! It seems that Okta would have to add the link header to the Access-Control-Expose-Headers response header, so that it can be accessed in CORS requests!?
Yup, @fes, you appear to be correct. We’ve filed a ticket internally (OKTA-357710) to get this header accessible in CORS requests.
Let me know if there are any other headers returned by Okta that you would want available when making AJAX requests so I can add it to the list of headers we should return to support this use case.
Okay thanks, that sounds great! So far, the link header was the only one I needed.
However, please make sure that the link header will not only be available for the /api/v1/users endpoint but also for other endpoints that support pagination, such as /api/v1/groups/${groupId}/users.
Can you already estimate when this ticket will be done?