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
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
}
}
}
User | Count |
---|---|
12 | |
12 | |
7 | |
6 | |
5 |