Dev
Dev

Reputation: 1

How to get all products and pagination in Shopify REST JS

I want to put all the products from one store in shopify to my database. But i can only get 250 products. I don't understand how to use pagination/page_info as explained in their documentation.

https://xxx.myshopify.com/admin/products/count.json
{
    "count": 492
}

const client = new Shopify.Clients.Rest(store.shop_name + ".myshopify.com", store.access_token); 

let data = await client.get({
      path: 'admin/products/count.json',
      query: {limit: 250}
    })

if i use page_info = abcdefg and then try for next page page_info = hijklmn, it both get the same value. pls help me to understand..

Upvotes: 0

Views: 2474

Answers (1)

Nguyen Quang Anh
Nguyen Quang Anh

Reputation: 21

You can using since_id to pagination https://shopify.dev/api/admin-rest/unstable/resources/product#get-products

Example: first request response 250 products => get the last id of the product returned

secord request: you must add params since_id (id of above)

In short: you can fetch all product same with count when call api https://xxx.myshopify.com/admin/products/count.json

Upvotes: 1

Related Questions