Paginate the 2019-07 REST Product API

Solved

Paginate the 2019-07 REST Product API

Giulio1
Excursionist
31 3 7

I switched to the 19/07 version of the product API and noticed that passing the page parameter with the endpoint will generate an error:

{"errors":{"page":"page cannot be passed."}}

 

Is the pagination functionality changed in this new version?

Using the 2019-04 works sweetly.

 

Thank you

Accepted Solution (1)
Giulio1
Excursionist
31 3 7

This is an accepted solution.

To sum up:

The page parameter was dropped from all the REST Admin API endpoints (Some in the 07/2019 and the rest in the 10/2019 release)

Now  in order to navigate the API response you will need to parse the HTTP LINK response header, which will contain if they exists, the URLs to the NEXT and PREVIOUS page. You can also set the LIMIT parameter in the HTTP LINK header.

Check:

Page-based pagination replaced by cursor-based pagination across multiple REST endpoints (Shopify)

Making requests to paginated REST Admin API endpoints (Shopify)

The HTTP Link entity-header field (MDN)

RFC 5988, section 5: The Link Header Field (IETF)

 

Addendum:

This has basically killed async requesting as now you have to wait a request's response before you can send another one.

 

View solution in original post

Replies 21 (21)

Busfox
Shopify Staff (Retired)
628 49 110

Hi @Giulio1,

 

We replaced page-based pagination for a number of endpoints in the 2019-07 version. This was done in favour of a much more performant method of pagination we've also released for these endpoints called cursor-based pagintion. We've released this guide on how to make calls using cursor-based pagination. The TLDR is that you need to look for the "Link" response header in your requests. The value of this header will be a link to both the next and previous page of results in the following format.

 

#...
Link: "<https://{shop}.myshopify.com/admin/api/{version}/products.json?page_info={page_info}&limit={limit}>; rel={next}, 
<https://{shop}.myshopify.com/admin/api/{version}/products.json?page_info={page_info}&limit={limit}>; rel={previous}" #...

That being said, you can continue making requests with the page param using the 2019-04 version until it is no longer supported with the release of 2020-04.

 

Let me know if you have any lingering questions or concerns.

 

Cheers,

To learn more visit the Shopify Help Center or the Community Blog.

Giulio1
Excursionist
31 3 7

Thank you @Busfox 

 

That is pretty clear 

jeffBlum_ffa
Visitor
3 0 0

HI 

 

We are not getting Link header in response headers returned by shopify while calling orders api below are the headers we are getting

 

1.We are calling orders api orders.json which returns orders all fine but we dont have any way to get second page of orders and documentation says we will get link header that will mention page_info param but api is not returning any link header or page_info as you can see below in response headers

 

HTTP/1.1 200 OK
Date: Mon, 02 Sep 2019 06:04:06 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=daaa7a5d79a531ae7a3dfa4f59a13dc5d1567404245; expires=Tue, 01-Sep-20 06:04:05 GMT; path=/; domain=.myshopify.com; HttpOnly
X-Sorting-Hat-PodId: 84
X-Sorting-Hat-ShopId: 7382728789
Vary: Accept-Encoding
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 7382728789
X-ShardId: 84
X-Stats-UserId: 
X-Stats-ApiClientId: 2972013
X-Stats-ApiPermissionId: 115969425493
X-Shopify-API-Terms: By accessing or using the Shopify API you agree to the Shopify API License and Terms of Use at https://www.shopify.com/legal/api-terms
HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/40
X-Shopify-Shop-Api-Call-Limit: 1/40
X-Shopify-API-Version: 2019-10
Strict-Transport-Security: max-age=7889238
X-Request-Id: c69c7392-e281-4733-9884-775df38d0825
X-Shopify-Stage: production
Content-Security-Policy: default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://js.braintreegateway.com https://c.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=index&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Forders&source%5Bsection%5D=admin_api&source%5Buuid%5D=c69c7392-e281-4733-9884-775df38d0825
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block; report=/xss-report?source%5Baction%5D=index&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Forders&source%5Bsection%5D=admin_api&source%5Buuid%5D=c69c7392-e281-4733-9884-775df38d0825
X-Dc: gcp-us-east1,gcp-us-east1
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 50fd48d78f90d5f8-BOM

 

Giulio1
Excursionist
31 3 7

It looks like you are using the 2019-10 version of the API which is unstable and shouldn't be used for production.

Maybe that is causing the problem.

@jeffBlum_ffa try to use the 2019-07 version.

 

jeffBlum_ffa
Visitor
3 0 0

@Giulio1 wrote:

It looks like you are using the 2019-10 version of the API which is unstable and shouldn't be used for production.

Maybe that is causing the problem.

@jeffBlum_ffa try to use the 2019-07 version.

 


Tried that as well here is the result @Giulio1 @Busfox 

 

HTTP/1.1 200 OK
Date: Mon, 02 Sep 2019 09:22:58 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=d350db241396c03c9acc0fecb395410491567416177; expires=Tue, 01-Sep-20 09:22:57 GMT; path=/; domain=.myshopify.com; HttpOnly
X-Sorting-Hat-PodId: 84
X-Sorting-Hat-ShopId: 7382728789
Vary: Accept-Encoding
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 7382728789
X-ShardId: 84
X-Stats-UserId: 
X-Stats-ApiClientId: 2972013
X-Stats-ApiPermissionId: 115969425493
X-Shopify-API-Terms: By accessing or using the Shopify API you agree to the Shopify API License and Terms of Use at https://www.shopify.com/legal/api-terms
HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/40
X-Shopify-Shop-Api-Call-Limit: 1/40
X-Shopify-API-Version: 2019-07
Strict-Transport-Security: max-age=7889238
X-Shopify-Stage: production
Content-Security-Policy: default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://js.braintreegateway.com https://c.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=index&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Forders&source%5Bsection%5D=admin_api&source%5Buuid%5D=d3cd8feb-bf9f-482a-9ee2-1d7fa0b5b987
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block; report=/xss-report?source%5Baction%5D=index&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Forders&source%5Bsection%5D=admin_api&source%5Buuid%5D=d3cd8feb-bf9f-482a-9ee2-1d7fa0b5b987
X-Dc: gcp-us-central1,gcp-us-east1,gcp-us-east1
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
X-Request-ID: d3cd8feb-bf9f-482a-9ee2-1d7fa0b5b987
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 50fe6c26ffcad9b8-SIN

@g 

jeffBlum_ffa
Visitor
3 0 0

@Giulio1 

 

Tried 2019-07 version as well but no luck 😞

 

HTTP/1.1 200 OK
Date: Mon, 02 Sep 2019 09:22:58 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=d350db241396c03c9acc0fecb395410491567416177; expires=Tue, 01-Sep-20 09:22:57 GMT; path=/; domain=.myshopify.com; HttpOnly
X-Sorting-Hat-PodId: 84
X-Sorting-Hat-ShopId: 7382728789
Vary: Accept-Encoding
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 7382728789
X-ShardId: 84
X-Stats-UserId: 
X-Stats-ApiClientId: 2972013
X-Stats-ApiPermissionId: 115969425493
X-Shopify-API-Terms: By accessing or using the Shopify API you agree to the Shopify API License and Terms of Use at https://www.shopify.com/legal/api-terms
HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/40
X-Shopify-Shop-Api-Call-Limit: 1/40
X-Shopify-API-Version: 2019-07
Strict-Transport-Security: max-age=7889238
X-Shopify-Stage: production
Content-Security-Policy: default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://js.braintreegateway.com https://c.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=index&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Forders&source%5Bsection%5D=admin_api&source%5Buuid%5D=d3cd8feb-bf9f-482a-9ee2-1d7fa0b5b987
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block; report=/xss-report?source%5Baction%5D=index&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Forders&source%5Bsection%5D=admin_api&source%5Buuid%5D=d3cd8feb-bf9f-482a-9ee2-1d7fa0b5b987
X-Dc: gcp-us-central1,gcp-us-east1,gcp-us-east1
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
X-Request-ID: d3cd8feb-bf9f-482a-9ee2-1d7fa0b5b987
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 50fe6c26ffcad9b8-SIN
Busfox
Shopify Staff (Retired)
628 49 110

Hi @jeffBlum_ffa,

 

If you're targeting the 2019-10 version of the order index endpoint, you should definitely be seeing a link header assuming there is a next page to be linked to. Does your response set have a second page of results?

To learn more visit the Shopify Help Center or the Community Blog.

Giulio1
Excursionist
31 3 7

@jeffBlum_ffa 

I had a look at the docs and the 2019-07 Order API still uses the pagination by page parameter.

 

page 
DEPRECATED

The page of results to show.

Removed in version 2019-10. Use cursor-based pagination instead.

 

So, for now just pass the good old page param: ?page=N

I understand that you may want to uniform all your systems to the new cursor-based pagination, but the 19-07 is supported till 07/2020 so no rush.

kenil88
Visitor
2 0 0

@jeffBlum_ffa how to use cursor based pagination?

 

can you please explain?

 

Did not understand how to use Link?

 

Thanks

Giulio1
Excursionist
31 3 7

Hi @jeffBlum_ffa

 

Did the older version on the API worked?

Do you have more than 50 orders in your store?

kenil88
Visitor
2 0 0

No i am using 2019-07 only. 

 

not for order. i want to use for products. 

 

pagination want to use. i have 100 products i dont want to load 100 products in 1 request.

 

thanks

Alex_Harper
Shopify Partner
1 0 2

I also wasn't getting the link header when performing a get request and figured out the solution.

 

The solution was to state the API Version in the get request URL ex:

setting the API version to 2019-10 in my private app settings then using this URL for get request did not produce the link header: https://key:pass@my-store.myshopify.com/admin/products.json

 

All I had to do to get the link header was include the API version in the URL ex: https://key:pass@my-store.myshopify.com/admin/api/2019-10/products.json

 

 

 

 

Giulio1
Excursionist
31 3 7

This is an accepted solution.

To sum up:

The page parameter was dropped from all the REST Admin API endpoints (Some in the 07/2019 and the rest in the 10/2019 release)

Now  in order to navigate the API response you will need to parse the HTTP LINK response header, which will contain if they exists, the URLs to the NEXT and PREVIOUS page. You can also set the LIMIT parameter in the HTTP LINK header.

Check:

Page-based pagination replaced by cursor-based pagination across multiple REST endpoints (Shopify)

Making requests to paginated REST Admin API endpoints (Shopify)

The HTTP Link entity-header field (MDN)

RFC 5988, section 5: The Link Header Field (IETF)

 

Addendum:

This has basically killed async requesting as now you have to wait a request's response before you can send another one.

 

jam_chan
Shopify Partner
909 23 185

Previously, I can use the page & limit parameters to visit the X-th page I want. I cannot do so with the new API?

BYOB - Build Your Own Bundles, SPO - SEO App to research keywords & edit social link preview
Giulio1
Excursionist
31 3 7

Try to export all the products

Order them by product id

and then use the ?since_id=

This kinda recreates the old pagination

 

Jivan_Suhagiya
Shopify Partner
595 82 126

Hi,
Anyone know how to parse link data in PHP? so I can get proper next and previous page links?

If helpful then please Like and Accept Solution.
Email: suhagiyajivan1992@gmail.com
Skype: jivan.suhagiya
First kind of Checkout Reminder APP: https://apps.shopify.com/checkout-reminder
Giulio1
Excursionist
31 3 7

I am using this function to navigate to the next link

It's in VBA but should be easy to translate it.

 

Function getNextPageURL(ByRef linkHeader As String) As String
    Dim linkArray() As String: linkArray = Split(linkHeader, ",")
    For Each link In linkArray
        link = Trim(link)
        Dim linkfields() As String: linkfields = Split(link, ">;")
        If linkfields(1) Like "*next*" Then
            getNextPageURL = Right(linkfields(0), Len(linkfields(0)) - 1)
            Exit Function
        Else
            getNextPageURL = ""
        End If
    Next link
End Function

It only finds the next link as I never need to go back

Also I wrote this specifically for Shopify APIs so there are good chances that it won't work with other applications.

Alex
Shopify Staff
1561 81 342

@Jivan_Suhagiya I answered a similar question elsewhere today, try preg_match():

 

preg_match("/<(.*)>; rel={next}/", $link_str, $matches);

$matches[1] will in the above case be the next link. There's probably a better expression to use, but that works for me in PHP.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

TheBarn
Shopify Partner
7 0 2

We found this variation of preg_match worked better in PHP

preg_match('/<([^<]*)>; rel="next"/', $header, $matches);
$next = $matches[1];
mayurs
Shopify Partner
4 0 0

It's working only at first place, second time I am getting the below error : 

{
    "errors": {
        "order""order cannot be passed when page_info is present. See https://help.shopify.com/api/guides/paginated-rest-results for more information."
    }
}
 
This is the URL request which I have received in header link:
https://{{store_name}}.myshopify.com/admin/api/2019-07/products.json?order=inventory_total+desc&limit=50&page_info=eyJvcmRlciI6ImludmVudG9yeV90b3RhbCBkZXNjIiwibGFzdF9pZCI6NDQ3MTY2OTI2MDQyMSwibGFzdF92YWx1ZSI6MCwiZGlyZWN0aW9uIjoibmV4dCJ9

Let me know how to resolve this ? 
 
Thanks,
Mayur

radheshyam_kori
Visitor
1 0 0

This is the code in php which might be helpful to you, to fetch the records in pagination using the limit and retrieving the Next URL and Previous URL to display the records page wise.

<html>
<head>
<title>Displaying All the Products Records Created / Updated from 25 June 2020 using Shopify API with Pagination</title>
</head>
<body>
<h3 align="center">Displaying All the Products Records Created / Updated from 25 June 2020 using Shopify API with Pagination</h3>
</body>
</html>
<?php
// url format for private app : https://{apikey}:{password}@{hostname}/admin/api/{version}/{resource}.json
$api_key = "4a4b367388d6a342feedef5b8a2d2862";
$password = "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";
//$shop = "radhe-online-store";
$shop = "radheshyampkori";
//$api_endpoint = "/admin/api/2020-04/products.json?status=any";
//$api_endpoint = "/admin/api/2020-04/products.json?presentment_currencies=USD";
//$api_endpoint = "/admin/api/2020-04/products/count.json";
$api_endpoint = "/admin/api/2020-04/products.json?status=any&limit=2&created_at_min=2020-06-25T00:00:01&updated_at_min=2020-06-25T00:00:01";
//$url = "https://" . $api_key .":".$password ."@". $shop . ".myshopify.com" . $api_endpoint;

$i = 1; // initializing count to display the page nos
echo "Records of Page Nos: ".$i; echo "</br>";
echo "================="; echo "</br>"; echo "</br>";echo "</br>";

// Passing the parameters to function to get the Response Headers and 2 Records of Customers per page
$product_data = get_response_data($api_key, $password, $shop, $api_endpoint);
//echo "Customer Data of the store url: "; echo "<pre>";print_r($product_data); echo "</pre>";

$url_next = $product_data[0]; // Obtaining and storing the URL to display the Next page Records

$next_rel_link = $product_data[1]; // Obtaining and Storing rel="next" used to check whether more Next pages exists to display records

$url_previous = $product_data[2]; // Obtaining and storing the URL to display the Previous page Records

/** Obtaining and Storing rel="previous" used to check whether more Previous pages exists to display records **/

$previous_rel_link = $product_data[3];

$i = 2; // initializing count to display the page nos
while($next_rel_link != '')
{

$explode_pagination_url = explode("?",$url_next);
$api_endpoint_limit_portion = $explode_pagination_url[1];
$api_endpoint = "/admin/api/2020-04/customers.json?".$api_endpoint_limit_portion;
echo "Records of Page Nos: ".$i; echo "</br>";
echo "================="; echo "</br>"; echo "</br>";echo "</br>";

/** Passing the URL, Paramenters along with endpoint for the Next Page URL to display next set of records **/
$product_data = get_response_data($api_key, $password, $shop, $api_endpoint);
$url_next = $product_data[0]; // Obtaining and storing the URL to display the Next page Records
$url = $url_next;
$next_rel_link = $product_data[1]; // Obtaining and Storing rel="next" used to check whether more Next pages exists to display records
$url_previous = $product_data[2]; // Obtaining and storing the URL to display the Previous page Records
/** Obtaining and Storing rel="previous" used to check whether more Previous pages exists to display records **/
$previous_rel_link = $product_data[3];
$i = $i + 1; // Incrementing the Page count
}

function get_response_data($api_key, $password, $shop, $api_endpoint)
{
$url = "https://" . $api_key .":".$password ."@". $shop . ".myshopify.com" . $api_endpoint;

echo "Latest URL"; echo "</br>";
echo $url; echo "</br>";
if (!function_exists('curl_init'))
{
die('CURL is not installed or it is not loaded!');
}
$shopcurl = curl_init();
curl_setopt($shopcurl, CURLOPT_URL, $url);
curl_setopt($shopcurl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($shopcurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($shopcurl, CURLOPT_VERBOSE, 0);
curl_setopt($shopcurl, CURLOPT_HEADER, 1);
curl_setopt($shopcurl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($shopcurl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec ($shopcurl);
curl_close ($shopcurl);
echo "<pre>";print_r($response); echo "</pre>";
$responseHeaders = get_headers($url,1);
// echo "<pre>";print_r($responseHeaders); echo "</pre>";
$next_link = "";
$previous_link = "";
$url_for_next_records_with_pagination = "";
$url_for_previous_records_with_pagination = "";
if(array_key_exists('Link',$responseHeaders))
{
// echo "Link exists";echo "</br>";
$link = $responseHeaders['Link']; // retriving the Value of the Link including the Next and Previous URLs
$link0 = $responseHeaders['Link'][0];
$link1 = $responseHeaders['Link'][1];

$checking_rel_previous_exists_with_location = strpos($link,'rel="previous"',0); // checking whether rel="previous" exists
$checking_rel_next_exists_with_location = strpos($link,'rel="next"',0); // checking whether rel="next" exists


if(!empty($checking_rel_previous_exists_with_location))
{
$pos_first_char_for_next_in_link = strpos($link, '<', 1); // finding position of < before the URL from the Link
/** finding position of > after the URL from the Link **/
$pos_last_char_for_next_in_link = strpos($link, '>', $pos_first_char_for_next_in_link);
$retrieved_next_url = substr($link, $pos_first_char_for_next_in_link + 1, -13); // Retrieving the Next URL
$explode_value_of_pagination_url = explode(";",$link);
$first_portion_of_Link = $explode_value_of_pagination_url[0];
$previous_portion_of_Link = $explode_value_of_pagination_url[1];
$end_portion_of_Link = $explode_value_of_pagination_url[2]; // Storing the rel="next" in a variable

}
else
{
//echo "rel Previous does not exists";
$pos_first_char_in_link = strpos($link, '<', 0); // finding position of < before the URL from the Link
/** finding position of > after the URL from the Link **/
$pos_last_char_in_link = strpos($link, '>', 0);
$retrieved_next_url = substr($link, $pos_first_char_in_link + 1, $pos_last_char_in_link - 1); // Retrieving Next URL
$explode_value_of_pagination_url = explode(";",$link);
$first_portion_of_Link = $explode_value_of_pagination_url[0];
$end_portion_of_Link = $explode_value_of_pagination_url[1]; // Storing the rel="next" in a variable
}

}
$url_for_next_records_with_pagination = $retrieved_next_url; // Storing the URL to be used to display Next page records
$next_link = $end_portion_of_Link; // Storing the rel="next" in a variable to check further Next page records exists
return array($url_for_next_records_with_pagination, $next_link, $url_for_previous_records_with_pagination, $previous_link);
}
?>