I recently took over updating a website for someone and I am dealing with their old code. It looks like I have to update the pagination. I am using python 3.5 and I am just wondering how to start with this.
productCount = shopify.Product.count() #print(productCount) #TESTING i = 1 pages = (productCount / 50) + 2 #pages = (productCount / 250) + 1 #TESTING, use for partial listing requests to speed up products = shopify.Product.find(page=i) print('page ' + str(i)) i+=1 while( i < pages ): products += shopify.Product.find(page=i) products += (requests.get('https:/private:firstname.lastname@example.org/admin/api/2019-10/products.json?limit=250&page='.i)) print("page " + str(i)) i+=1 print(products) return products
Hey @johnbernards ,
Assuming that you are using the official Shopify Python API library, support for the newest form of pagination (called cursor-based pagination) has been added to version 6.00 (https://github.com/Shopify/shopify_python_api/pull/352)
Here is some starter code for how to get the next page of Products using the newest form of pagination:
import shopify page1 = shopify.Product.find() if page1.has_next_page(): page2 = page1.next_page() # to persist across requests you can use next_page_url and previous_page_url next_url = page1.next_page_url page2 = shopify.Product.find(from_=next_url)
Hassain | Developer Support Specialist @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Click Accept as Solution