I'm trying to implement Okta's pagination for their API endpoint List Users. It looks like in order to paginate one must get the next link via their incoming headers from their response. When executing their List Users API endpoint via the command line's cUrl or Postman, everything looks great in the header, but the issue is when running it from a PHP script using cUrl or guzzle, the Link html tags are stripped from the header as shown below:
HTTP/1.1 200 OK
Date: Thu, 03 Nov 2016 19:36:34 GMT
Server: nginx
Content-Type: application/json;charset=UTF-8
Vary: Accept-Encoding
X-Okta-Request-Id: WBuTwqhxlYz3iu5PY1jqHQZZBMU
X-Rate-Limit-Limit: 1200
X-Rate-Limit-Remaining: 1198
X-Rate-Limit-Reset: 1478201841
Cache-Control: no-cache, no-store
Pragma: no-cache
Expires: 0
Link: ; rel="self"
Strict-Transport-Security: max-age=315360000
The header should instead looks as:
HTTP/1.1 200 OK
Content-Type: application/json
Link: <https://your-domain.okta.com/api/v1/users?limit=200>; rel="self"
Link: <https://your-domain.okta.com/api/v1/users? after=00ud4tVDDXYVKPXKVLCO&limit=200>; rel="next"
I searched for a while and can't find a solution. Has anyone come across this issue before? Thanks in advance.
Make sure that you are including the Accept: application/json
header in your requests. My guess is that PHP's cURL or Guzzle are using a different MIME type, like text/plain
.
I was able to reproduce your issue with the following curl
command, which gives no results:
curl --verbose \
--header "Authorization: SSWS ${API_KEY}" \
--header "Content-Type: application/json" \
--header "Accept: text/plain" \
"https://${ORG}/api/v1/users?limit=1" 2>&1 | grep 'Link: '
However, if I change the Accept:
header to application/json
I do get the Link:
header:
curl --verbose \
--header "Authorization: SSWS ${API_KEY}" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
"https://${ORG}/api/v1/users?limit=1" 2>&1 | grep 'Link: '
< Link: <https://example.okta.com/api/v1/users?limit=1>; rel="self"
< Link: <https://example.okta.com/api/v1/users?after=012a3b456cdefgHijK7l8&limit=1>; rel="next"