get all product in a collection

Highlighted
New Member
5 0 0

Hi Team,

I would like to get all product ids belonging to a collection 

To get the count I used :GET /admin/products/count.json?collection_id=<myid>

it return 122 products in the collection but when I am trying to read the product ids using 

GET  /admin/products.json?collection_id=<collectionid> but it only return 50  

I am not sure if that's the correct api call url. 

Can you please share how can I get the product listing for a collection

0 Likes
Highlighted
Shopify Partner
2 0 0

You can try adding an additional param to your GET request. 
Example: "/admin/products/count.json?collection_id=123&limit=250"

0 Likes
Highlighted

1. you missed the limit parameter in your API call

2. to get all products, you need to use a while loop to go through all pages, each page you will get 250. Just append the products into an array

SPO - SEO App to research keywords & edit social link preview
0 Likes
Highlighted
Shopify Partner
520 38 109

Seeing that the Shopify API's for paginated responses has changed in favor of cursor-based pagination, requesting the results requires parsing the response headers to determine the next page to fetch.

Personally it would be a lot easier to just query via the GraphQL API's bulk operation. Described here --> https://shopify.dev/tutorials/perform-bulk-operations-with-admin-api. Below is an example of requesting all product ID's and titles for any items in the Jewelry collection. Once the bulk operation has completed then just retrieve the file via its URL.

mutation {
  bulkOperationRunQuery(
   query: """
    {
      collectionByHandle(handle: "Jewelry") {
					products {
        		edges {
          		node {
            		id
            		title
          		}
        	}
      	}
    	}
	}
    """
  ) {
    bulkOperation {
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}
0 Likes