Link parameter from response header for pagination is empty

Hi,

I’m trying to work pagination for list users. But in response header I get Link parameter is empty,
link: ; rel=“self”
link: ; rel=“next”

If I ran the same through Postman, it gives me the correct link.

Below is my code,

    $sUrl = 'https://{subdomain}.oktapreview.com/api/v1/users?filter=status%20eq%20%22ACTIVE%22&limit=5';
    $request_headers = array();
    $request_headers[] = 'Accept: application/json';
    $request_headers[] = 'Content-Type: application/json';
    $request_headers[] = 'Authorization: SSWS {APIKEY}';

    $ch = curl_init($sUrl);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
    $response = curl_exec($ch);

    $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $header = substr($response, 0, $header_size);
    $body = substr($response, $header_size);

    echo '<pre>';
    print_r($header);
    echo '</pre>';
    echo '<pre>';
    print_r(json_decode($body));
    echo '</pre>';

Let me know if I’m missing anything.

Thanks!

Hi @amits.contentserv

I have tested this script on my end and I did not find any issues, the next page was returned successfully in the body. Please check also page source as the browser might render the next page as a tag and, as such, not display it.

Alternatively, you can use something like the following to get the next page

$sUrl = 'https://dragos.okta.com/api/v1/users?filter=status%20eq%20%22ACTIVE%22&limit=5';
$request_headers = array();
$request_headers[] = 'Accept: application/json';
$request_headers[] = 'Content-Type: application/json';
$request_headers[] = 'Authorization: SSWS <REDACTED>';

$ch = curl_init($sUrl);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
$response = curl_exec($ch);

$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);

if(preg_match('/Link: <(.*)>; rel=\"next/', $header, $matches))
{
    echo "Next page URL is: " . $matches[1];
}
1 Like

Hi @dragos,

You were correct, it is rendering as a tag.
Appreciate your help.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.