collectionByHandle
Requires access scope.
Return a collection by its handle. Use instead.
Arguments
- Anchor to handlehandle•String!required
The handle of the collection.
Anchor to Possible returnsPossible returns
- Anchor to CollectionCollection•
Represents a group of products that can be displayed in online stores and other sales channels in categories, which makes it easy for customers to find them. For example, an athletics store might create different collections for running attire, shoes, and accessories.
Collections can be defined by conditions, such as whether they match certain product tags. These are called smart or automated collections.
Collections can also be created for a custom group of products. These are called custom or manual collections.
- Retrieve a collection by a handle that doesn't exist
- Retrieve a collection with five of its best-selling products by its handle
- Retrieve the ID of a collection with a specified handle
Examples
query {
collectionByHandle(handle: "there is no collection with a handle like this") {
id
title
products(first: 5, reverse: true) {
edges {
node {
id
title
createdAt
priceRangeV2 {
minVariantPrice {
amount
currencyCode
}
maxVariantPrice {
amount
currencyCode
}
}
}
}
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "query { collectionByHandle(handle: \"there is no collection with a handle like this\") { id title products(first: 5, reverse: true) { edges { node { id title createdAt priceRangeV2 { minVariantPrice { amount currencyCode } maxVariantPrice { amount currencyCode } } } } } } }"
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
query {
collectionByHandle(handle: "there is no collection with a handle like this") {
id
title
products(first: 5, reverse: true) {
edges {
node {
id
title
createdAt
priceRangeV2 {
minVariantPrice {
amount
currencyCode
}
maxVariantPrice {
amount
currencyCode
}
}
}
}
}
}
}`,
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: `query {
collectionByHandle(handle: "there is no collection with a handle like this") {
id
title
products(first: 5, reverse: true) {
edges {
node {
id
title
createdAt
priceRangeV2 {
minVariantPrice {
amount
currencyCode
}
maxVariantPrice {
amount
currencyCode
}
}
}
}
}
}
}`,
});
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 {
collectionByHandle(handle: "there is no collection with a handle like this") {
id
title
products(first: 5, reverse: true) {
edges {
node {
id
title
createdAt
priceRangeV2 {
minVariantPrice {
amount
currencyCode
}
maxVariantPrice {
amount
currencyCode
}
}
}
}
}
}
}
QUERY
response = client.query(query: query)