Paginate the 2019-07 REST Product API

Solved
Excursionist
19 1 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
Shopify Partner
135 2 12

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

0 Likes
Excursionist
19 1 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
1460 66 217

@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