Paginate the 2019-07 REST Product API

Solved
Excursionist
25 3 3

Hi @jeffBlum_ffa

 

Did the older version on the API worked?

Do you have more than 50 orders in your store?

0 Likes
New Member
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

0 Likes
Highlighted
Shopify Partner
156 4 14

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

0 Likes
Excursionist
25 3 3

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.

1 Like
Shopify Staff
Shopify Staff
1555 79 240

@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.

0 Likes
Shopify Partner
1 0 1

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

 

 

 

 

1 Like

Success.

Excursionist
25 3 3

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.

 

0 Likes