--- title: collection - GraphQL Admin description: |- Retrieves a [collection](https://shopify.dev/docs/api/admin-graphql/latest/objects/Collection) by its ID. A collection represents a grouping of [products](https://shopify.dev/docs/api/admin-graphql/latest/objects/Product) that merchants can display and sell as a group in their [online store](https://shopify.dev/docs/apps/build/online-store) and other [sales channels](https://shopify.dev/docs/apps/build/sales-channels). Use the `collection` query when you need to: - Manage collection publishing across sales channels - Access collection metadata and SEO information - Work with collection rules and product relationships A collection can be either a custom ([manual](https://help.shopify.com/manual/products/collections/manual-shopify-collection)) collection where products are manually added, or a smart ([automated](https://help.shopify.com/manual/products/collections/automated-collections)) collection where products are automatically included based on defined rules. Each collection has associated metadata including title, description, handle, image, and [metafields](https://shopify.dev/docs/apps/build/custom-data/metafields). api_version: 2025-10 api_name: admin type: query api_type: graphql source_url: html: https://shopify.dev/docs/api/admin-graphql/latest/queries/collection md: https://shopify.dev/docs/api/admin-graphql/latest/queries/collection.md --- # collection query Retrieves a [collection](https://shopify.dev/docs/api/admin-graphql/latest/objects/Collection) by its ID. A collection represents a grouping of [products](https://shopify.dev/docs/api/admin-graphql/latest/objects/Product) that merchants can display and sell as a group in their [online store](https://shopify.dev/docs/apps/build/online-store) and other [sales channels](https://shopify.dev/docs/apps/build/sales-channels). Use the `collection` query when you need to: * Manage collection publishing across sales channels * Access collection metadata and SEO information * Work with collection rules and product relationships A collection can be either a custom ([manual](https://help.shopify.com/manual/products/collections/manual-shopify-collection)) collection where products are manually added, or a smart ([automated](https://help.shopify.com/manual/products/collections/automated-collections)) collection where products are automatically included based on defined rules. Each collection has associated metadata including title, description, handle, image, and [metafields](https://shopify.dev/docs/apps/build/custom-data/metafields). ## Arguments * id [ID!](https://shopify.dev/docs/api/admin-graphql/latest/scalars/ID) required The ID of the `Collection` to return. *** ## Possible returns * Collection [Collection](https://shopify.dev/docs/api/admin-graphql/latest/objects/Collection) The `Collection` object represents a group of [products](https://shopify.dev/docs/api/admin-graphql/latest/objects/Product) that merchants can organize to make their stores easier to browse and help customers find related products. Collections serve as the primary way to categorize and display products across [online stores](https://shopify.dev/docs/apps/build/online-store), [sales channels](https://shopify.dev/docs/apps/build/sales-channels), and marketing campaigns. There are two types of collections: * **[Custom (manual) collections](https://help.shopify.com/manual/products/collections/manual-shopify-collection)**: You specify the products to include in a collection. * **[Smart (automated) collections](https://help.shopify.com/manual/products/collections/automated-collections)**: You define rules, and products matching those rules are automatically included in the collection. The `Collection` object provides information to: * Organize products by category, season, or promotion. * Automate product grouping using rules (for example, by tag, type, or price). * Configure product sorting and display order (for example, alphabetical, best-selling, price, or manual). * Manage collection visibility and publication across sales channels. * Add rich descriptions, images, and metadata to enhance discovery. *** Note Collections are unpublished by default. To make them available to customers, use the [`publishablePublish`](https://shopify.dev/docs/api/admin-graphql/latest/mutations/publishablePublish) mutation after creation. *** Collections can be displayed in a store with Shopify's theme system through [Liquid templates](https://shopify.dev/docs/storefronts/themes/architecture/templates/collection) and can be customized with [template suffixes](https://shopify.dev/docs/storefronts/themes/architecture/templates/alternate-templates) for unique layouts. They also support advanced features like translated content, resource feedback, and contextual publication for location-based catalogs. Learn about [using metafields with smart collections](https://shopify.dev/docs/apps/build/custom-data/metafields/use-metafield-capabilities). *** ## Examples * ### Retrieve a metafield associated with a collection #### Description Get the \[metafield]\(https\://shopify.dev/docs/apps/build/custom-data) value identified by \`my\_fields.subtitle\` on a specific collection. #### Query ```graphql query CollectionMetafield($namespace: String!, $key: String!, $ownerId: ID!) { collection(id: $ownerId) { subtitle: metafield(namespace: $namespace, key: $key) { value } } } ``` #### Variables ```json { "namespace": "my_fields", "key": "subtitle", "ownerId": "gid://shopify/Collection/841564295" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query CollectionMetafield($namespace: String!, $key: String!, $ownerId: ID!) { collection(id: $ownerId) { subtitle: metafield(namespace: $namespace, key: $key) { value } } }", "variables": { "namespace": "my_fields", "key": "subtitle", "ownerId": "gid://shopify/Collection/841564295" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query CollectionMetafield($namespace: String!, $key: String!, $ownerId: ID!) { collection(id: $ownerId) { subtitle: metafield(namespace: $namespace, key: $key) { value } } }`, { variables: { "namespace": "my_fields", "key": "subtitle", "ownerId": "gid://shopify/Collection/841564295" }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query CollectionMetafield($namespace: String!, $key: String!, $ownerId: ID!) { collection(id: $ownerId) { subtitle: metafield(namespace: $namespace, key: $key) { value } } } QUERY variables = { "namespace": "my_fields", "key": "subtitle", "ownerId": "gid://shopify/Collection/841564295" } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `query CollectionMetafield($namespace: String!, $key: String!, $ownerId: ID!) { collection(id: $ownerId) { subtitle: metafield(namespace: $namespace, key: $key) { value } } }`, "variables": { "namespace": "my_fields", "key": "subtitle", "ownerId": "gid://shopify/Collection/841564295" }, }, }); ``` #### Response ```json { "collection": { "subtitle": { "value": "Best of the best" } } } ``` * ### Retrieve a collection by ID #### Description Retrieve a specific \[collection]\(https\://shopify.dev/docs/api/admin-graphql/latest/objects/Collection) using its ID. The response returns the collection's basic information including its ID, title, handle, description, update timestamp, image details, and \[sort order]\(https\://shopify.dev/docs/api/admin-graphql/latest/enums/CollectionSortOrder). #### Query ```graphql query GetCollection($id: ID!) { collection(id: $id) { id title handle descriptionHtml updatedAt sortOrder image { url height width } } } ``` #### Variables ```json { "id": "gid://shopify/Collection/841564295" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query GetCollection($id: ID!) { collection(id: $id) { id title handle descriptionHtml updatedAt sortOrder image { url height width } } }", "variables": { "id": "gid://shopify/Collection/841564295" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query GetCollection($id: ID!) { collection(id: $id) { id title handle descriptionHtml updatedAt sortOrder image { url height width } } }`, { variables: { "id": "gid://shopify/Collection/841564295" }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query GetCollection($id: ID!) { collection(id: $id) { id title handle descriptionHtml updatedAt sortOrder image { url height width } } } QUERY variables = { "id": "gid://shopify/Collection/841564295" } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `query GetCollection($id: ID!) { collection(id: $id) { id title handle descriptionHtml updatedAt sortOrder image { url height width } } }`, "variables": { "id": "gid://shopify/Collection/841564295" }, }, }); ``` #### Response ```json { "collection": { "id": "gid://shopify/Collection/841564295", "title": "IPods", "handle": "ipods", "descriptionHtml": "

The best selling ipod ever

", "updatedAt": "2008-02-02T00:00:00Z", "sortOrder": "MANUAL", "image": { "url": "https://cdn.shopify.com/s/files/1/0005/4838/0009/collections/ipod_nano_8gb.jpg?v=1750460312", "height": 456, "width": 123 } } } ``` * ### Retrieve a collection with its products #### Description Retrieve a \[collection]\(https\://shopify.dev/docs/api/admin-graphql/latest/objects/Collection) along with a list of its associated \[products]\(https\://shopify.dev/docs/api/admin-graphql/latest/objects/Product). The response includes the collection details and the first 10 products in the collection, with each product's ID and title. This is useful for displaying a collection page with its product listings. #### Query ```graphql query GetCollectionWithProducts($id: ID!) { collection(id: $id) { id title handle descriptionHtml products(first: 10) { nodes { id title handle } pageInfo { hasNextPage hasPreviousPage } } } } ``` #### Variables ```json { "id": "gid://shopify/Collection/841564295" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query GetCollectionWithProducts($id: ID!) { collection(id: $id) { id title handle descriptionHtml products(first: 10) { nodes { id title handle } pageInfo { hasNextPage hasPreviousPage } } } }", "variables": { "id": "gid://shopify/Collection/841564295" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query GetCollectionWithProducts($id: ID!) { collection(id: $id) { id title handle descriptionHtml products(first: 10) { nodes { id title handle } pageInfo { hasNextPage hasPreviousPage } } } }`, { variables: { "id": "gid://shopify/Collection/841564295" }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query GetCollectionWithProducts($id: ID!) { collection(id: $id) { id title handle descriptionHtml products(first: 10) { nodes { id title handle } pageInfo { hasNextPage hasPreviousPage } } } } QUERY variables = { "id": "gid://shopify/Collection/841564295" } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `query GetCollectionWithProducts($id: ID!) { collection(id: $id) { id title handle descriptionHtml products(first: 10) { nodes { id title handle } pageInfo { hasNextPage hasPreviousPage } } } }`, "variables": { "id": "gid://shopify/Collection/841564295" }, }, }); ``` #### Response ```json { "collection": { "id": "gid://shopify/Collection/841564295", "title": "IPods", "handle": "ipods", "descriptionHtml": "

The best selling ipod ever

", "products": { "nodes": [ { "id": "gid://shopify/Product/632910392", "title": "IPod Nano - 8GB", "handle": "ipod-nano" } ], "pageInfo": { "hasNextPage": false, "hasPreviousPage": false } } } } ``` * ### Retrieve a smart collection with its rules #### Description Retrieve a \[smart collection]\(https\://help.shopify.com/manual/products/collections/smart-collections) along with its automated \[rules]\(https\://help.shopify.com/manual/products/collections/smart-collections/conditions). Smart collections automatically include products that match specific conditions. The response includes the collection details and its rule set, which defines the conditions used to automatically populate the collection with products. #### Query ```graphql query GetSmartCollection($id: ID!) { collection(id: $id) { id title handle sortOrder ruleSet { appliedDisjunctively rules { column relation condition } } products(first: 5) { nodes { id title } } } } ``` #### Variables ```json { "id": "gid://shopify/Collection/482865238" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query GetSmartCollection($id: ID!) { collection(id: $id) { id title handle sortOrder ruleSet { appliedDisjunctively rules { column relation condition } } products(first: 5) { nodes { id title } } } }", "variables": { "id": "gid://shopify/Collection/482865238" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query GetSmartCollection($id: ID!) { collection(id: $id) { id title handle sortOrder ruleSet { appliedDisjunctively rules { column relation condition } } products(first: 5) { nodes { id title } } } }`, { variables: { "id": "gid://shopify/Collection/482865238" }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query GetSmartCollection($id: ID!) { collection(id: $id) { id title handle sortOrder ruleSet { appliedDisjunctively rules { column relation condition } } products(first: 5) { nodes { id title } } } } QUERY variables = { "id": "gid://shopify/Collection/482865238" } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `query GetSmartCollection($id: ID!) { collection(id: $id) { id title handle sortOrder ruleSet { appliedDisjunctively rules { column relation condition } } products(first: 5) { nodes { id title } } } }`, "variables": { "id": "gid://shopify/Collection/482865238" }, }, }); ``` #### Response ```json { "collection": { "id": "gid://shopify/Collection/482865238", "title": "Smart iPods", "handle": "smart-ipods", "sortOrder": "MANUAL", "ruleSet": { "appliedDisjunctively": false, "rules": [ { "column": "TYPE", "relation": "EQUALS", "condition": "Cult Products" } ] }, "products": { "nodes": [ { "id": "gid://shopify/Product/632910392", "title": "IPod Nano - 8GB" }, { "id": "gid://shopify/Product/921728736", "title": "IPod Touch 8GB" } ] } } } ``` * ### Retrieve a collection's publication status #### Description Check if a collection is published to a \[sales channel]\(https\://shopify.dev/docs/apps/build/sales-channels). The response includes publication status and publication-related fields. This is useful for determining collection visibility and managing which collections are available through your app. > Note: > You must have the \`read\_product\_listings\` access scope to retrieve publication information. #### Query ```graphql query GetCollectionPublicationStatus($id: ID!) { collection(id: $id) { id title publishedOnCurrentPublication publicationCount resourcePublicationsCount { count precision } } } ``` #### Variables ```json { "id": "gid://shopify/Collection/841564295" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query GetCollectionPublicationStatus($id: ID!) { collection(id: $id) { id title publishedOnCurrentPublication publicationCount resourcePublicationsCount { count precision } } }", "variables": { "id": "gid://shopify/Collection/841564295" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query GetCollectionPublicationStatus($id: ID!) { collection(id: $id) { id title publishedOnCurrentPublication publicationCount resourcePublicationsCount { count precision } } }`, { variables: { "id": "gid://shopify/Collection/841564295" }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query GetCollectionPublicationStatus($id: ID!) { collection(id: $id) { id title publishedOnCurrentPublication publicationCount resourcePublicationsCount { count precision } } } QUERY variables = { "id": "gid://shopify/Collection/841564295" } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `query GetCollectionPublicationStatus($id: ID!) { collection(id: $id) { id title publishedOnCurrentPublication publicationCount resourcePublicationsCount { count precision } } }`, "variables": { "id": "gid://shopify/Collection/841564295" }, }, }); ``` #### Response ```json { "collection": { "id": "gid://shopify/Collection/841564295", "title": "IPods", "publishedOnCurrentPublication": true, "publicationCount": 2, "resourcePublicationsCount": { "count": 2, "precision": "EXACT" } } } ``` * ### Try retrieving a non-existent collection #### Description Attempting to retrieve a collection that doesn't exist returns \`null\`. This demonstrates the expected behavior when querying for a non-existent collection ID. #### Query ```graphql query GetNonExistentCollection($id: ID!) { collection(id: $id) { id title handle } } ``` #### Variables ```json { "id": "gid://shopify/Collection/-1" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query GetNonExistentCollection($id: ID!) { collection(id: $id) { id title handle } }", "variables": { "id": "gid://shopify/Collection/-1" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query GetNonExistentCollection($id: ID!) { collection(id: $id) { id title handle } }`, { variables: { "id": "gid://shopify/Collection/-1" }, }, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query GetNonExistentCollection($id: ID!) { collection(id: $id) { id title handle } } QUERY variables = { "id": "gid://shopify/Collection/-1" } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `query GetNonExistentCollection($id: ID!) { collection(id: $id) { id title handle } }`, "variables": { "id": "gid://shopify/Collection/-1" }, }, }); ``` #### Response ```json { "collection": null } ``` [Open in GraphiQL](http://localhost:3457/graphiql?query=query%20CollectionMetafield\(%24namespace%3A%20String!%2C%20%24key%3A%20String!%2C%20%24ownerId%3A%20ID!\)%20%7B%0A%20%20collection\(id%3A%20%24ownerId\)%20%7B%0A%20%20%20%20subtitle%3A%20metafield\(namespace%3A%20%24namespace%2C%20key%3A%20%24key\)%20%7B%0A%20%20%20%20%20%20value%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D\&variables=%7B%0A%20%20%22namespace%22%3A%20%22my_fields%22%2C%0A%20%20%22key%22%3A%20%22subtitle%22%2C%0A%20%20%22ownerId%22%3A%20%22gid%3A%2F%2Fshopify%2FCollection%2F841564295%22%0A%7D) ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query CollectionMetafield($namespace: String!, $key: String!, $ownerId: ID!) { collection(id: $ownerId) { subtitle: metafield(namespace: $namespace, key: $key) { value } } }`, { variables: { "namespace": "my_fields", "key": "subtitle", "ownerId": "gid://shopify/Collection/841564295" }, }, ); const json = await response.json(); return json.data; } ``` ##### GQL ``` query CollectionMetafield($namespace: String!, $key: String!, $ownerId: ID!) { collection(id: $ownerId) { subtitle: metafield(namespace: $namespace, key: $key) { value } } } ``` ##### cURL ``` curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query CollectionMetafield($namespace: String!, $key: String!, $ownerId: ID!) { collection(id: $ownerId) { subtitle: metafield(namespace: $namespace, key: $key) { value } } }", "variables": { "namespace": "my_fields", "key": "subtitle", "ownerId": "gid://shopify/Collection/841564295" } }' ``` ##### React Router ``` import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query CollectionMetafield($namespace: String!, $key: String!, $ownerId: ID!) { collection(id: $ownerId) { subtitle: metafield(namespace: $namespace, key: $key) { value } } }`, { variables: { "namespace": "my_fields", "key": "subtitle", "ownerId": "gid://shopify/Collection/841564295" }, }, ); const json = await response.json(); return json.data; } ``` ##### Node.js ``` const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `query CollectionMetafield($namespace: String!, $key: String!, $ownerId: ID!) { collection(id: $ownerId) { subtitle: metafield(namespace: $namespace, key: $key) { value } } }`, "variables": { "namespace": "my_fields", "key": "subtitle", "ownerId": "gid://shopify/Collection/841564295" }, }, }); ``` ##### Ruby ``` session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query CollectionMetafield($namespace: String!, $key: String!, $ownerId: ID!) { collection(id: $ownerId) { subtitle: metafield(namespace: $namespace, key: $key) { value } } } QUERY variables = { "namespace": "my_fields", "key": "subtitle", "ownerId": "gid://shopify/Collection/841564295" } response = client.query(query: query, variables: variables) ``` ## Input variables JSON ```json { "namespace": "my_fields", "key": "subtitle", "ownerId": "gid://shopify/Collection/841564295" } ``` ## Response JSON ```json { "collection": { "subtitle": { "value": "Best of the best" } } } ```