Create a collection from an existing source
Description
Create a collection by linking an existing shareable source. Use `linkedSource` with a
`sourceId` when an app has already created a source that can be reused by one or more collections.
Query
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"title": "Collection from an existing source",
"sources": [
{
"linkedSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionCreate($collection: CollectionCreateInput!) { collectionCreate(collection: $collection) { collection { id title sources { __typename id title } } userErrors { field message } } }",
"variables": {
"collection": {
"title": "Collection from an existing source",
"sources": [
{
"linkedSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"title": "Collection from an existing source",
"sources": [
{
"linkedSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
},
},
);
const json = await response.json();
return json.data;
}
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
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"title": "Collection from an existing source",
"sources": [
{
"linkedSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"title": "Collection from an existing source",
"sources": [
{
"linkedSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"title": "Collection from an existing source",
"sources": [
{
"linkedSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/unstable/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"title": "Collection from an existing source",
"sources": [
{
"linkedSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001404",
"title": "Collection from an existing source",
"sources": [
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/129168209",
"title": "Shareable Source Owned By Shopify Web"
}
]
},
"userErrors": []
}
}
Create a collection from another collection
Description
Create a collection with a sub-collection source. The new collection includes products from another
collection through the `subCollection` source target.
Query
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionSubCollectionSource {
subCollection {
id
title
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollection": {
"title": "Featured products source",
"description": "Products from the featured collection.",
"subCollectionId": "gid://shopify/Collection/1007901140"
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionCreate($collection: CollectionCreateInput!) { collectionCreate(collection: $collection) { collection { id title sources { __typename id title ... on CollectionSubCollectionSource { subCollection { id title } } } } userErrors { field message } } }",
"variables": {
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollection": {
"title": "Featured products source",
"description": "Products from the featured collection.",
"subCollectionId": "gid://shopify/Collection/1007901140"
}
}
]
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionSubCollectionSource {
subCollection {
id
title
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollection": {
"title": "Featured products source",
"description": "Products from the featured collection.",
"subCollectionId": "gid://shopify/Collection/1007901140"
}
}
]
}
},
},
);
const json = await response.json();
return json.data;
}
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
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionSubCollectionSource {
subCollection {
id
title
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollection": {
"title": "Featured products source",
"description": "Products from the featured collection.",
"subCollectionId": "gid://shopify/Collection/1007901140"
}
}
]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionSubCollectionSource {
subCollection {
id
title
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollection": {
"title": "Featured products source",
"description": "Products from the featured collection.",
"subCollectionId": "gid://shopify/Collection/1007901140"
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionSubCollectionSource {
subCollection {
id
title
}
}
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollection": {
"title": "Featured products source",
"description": "Products from the featured collection.",
"subCollectionId": "gid://shopify/Collection/1007901140"
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/unstable/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionSubCollectionSource {
subCollection {
id
title
}
}
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollection": {
"title": "Featured products source",
"description": "Products from the featured collection.",
"subCollectionId": "gid://shopify/Collection/1007901140"
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001444",
"title": "Featured spring products",
"sources": [
{
"__typename": "CollectionSubCollectionSource",
"id": "gid://shopify/CollectionSubCollectionSource/1047893297",
"title": "Featured products source",
"subCollection": {
"id": "gid://shopify/Collection/1007901140",
"title": "Featured items"
}
}
]
},
"userErrors": []
}
}
Create a collection with an image
Description
Create a collection that includes an image. This example shows how to attach image details,
such as the source URL and alt text during the process of creating the collection.
The response returns the collection's ID, title, and other specified image details.
Query
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
image {
url
altText
}
}
}
}
Variables
{
"input": {
"title": "Collection with Image",
"image": {
"src": "tmp/26371970/collections/2fb4c50b-b04b-4ee8-a857-52b7ad9e5d2d/test_file.txt",
"altText": "A beautiful collection image"
}
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionCreate($input: CollectionInput!) { collectionCreate(input: $input) { userErrors { field message } collection { id title image { url altText } } } }",
"variables": {
"input": {
"title": "Collection with Image",
"image": {
"src": "tmp/26371970/collections/2fb4c50b-b04b-4ee8-a857-52b7ad9e5d2d/test_file.txt",
"altText": "A beautiful collection image"
}
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
image {
url
altText
}
}
}
}`,
{
variables: {
"input": {
"title": "Collection with Image",
"image": {
"src": "tmp/26371970/collections/2fb4c50b-b04b-4ee8-a857-52b7ad9e5d2d/test_file.txt",
"altText": "A beautiful collection image"
}
}
},
},
);
const json = await response.json();
return json.data;
}
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
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
image {
url
altText
}
}
}
}
QUERY
variables = {
"input": {
"title": "Collection with Image",
"image": {
"src": "tmp/26371970/collections/2fb4c50b-b04b-4ee8-a857-52b7ad9e5d2d/test_file.txt",
"altText": "A beautiful collection image"
}
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
image {
url
altText
}
}
}
}`,
"variables": {
"input": {
"title": "Collection with Image",
"image": {
"src": "tmp/26371970/collections/2fb4c50b-b04b-4ee8-a857-52b7ad9e5d2d/test_file.txt",
"altText": "A beautiful collection image"
}
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
image {
url
altText
}
}
}
}' \
--variables \
'{
"input": {
"title": "Collection with Image",
"image": {
"src": "tmp/26371970/collections/2fb4c50b-b04b-4ee8-a857-52b7ad9e5d2d/test_file.txt",
"altText": "A beautiful collection image"
}
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/unstable/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
image {
url
altText
}
}
}
}
`,
variables: {
"input": {
"title": "Collection with Image",
"image": {
"src": "tmp/26371970/collections/2fb4c50b-b04b-4ee8-a857-52b7ad9e5d2d/test_file.txt",
"altText": "A beautiful collection image"
}
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"userErrors": [],
"collection": {
"id": "gid://shopify/Collection/1063001426",
"title": "Collection with Image",
"image": {
"url": "https://cdn.shopify.com/s/files/1/2637/1970/collections/test_file.jpg?v=1781273014",
"altText": "A beautiful collection image"
}
}
}
}
Create a collection with multiple sources
Description
Create a collection with multiple sources. Each source can contribute products through conditions,
manual selections, or a combination of both.
Query
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
}
selections(first: 10) {
nodes {
product {
id
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"title": "Layered spring collection",
"sources": [
{
"source": {
"title": "Products tagged spring",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
}
]
}
}
},
{
"source": {
"title": "Featured product selections",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionCreate($collection: CollectionCreateInput!) { collectionCreate(collection: $collection) { collection { id title sources { __typename id title ... on CollectionConditionsSource { inclusion { matchType conditions { __typename } selections(first: 10) { nodes { product { id } } } } } } } userErrors { field message } } }",
"variables": {
"collection": {
"title": "Layered spring collection",
"sources": [
{
"source": {
"title": "Products tagged spring",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
}
]
}
}
},
{
"source": {
"title": "Featured product selections",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
}
selections(first: 10) {
nodes {
product {
id
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"title": "Layered spring collection",
"sources": [
{
"source": {
"title": "Products tagged spring",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
}
]
}
}
},
{
"source": {
"title": "Featured product selections",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
},
},
);
const json = await response.json();
return json.data;
}
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
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
}
selections(first: 10) {
nodes {
product {
id
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"title": "Layered spring collection",
"sources": [
{
"source": {
"title": "Products tagged spring",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
}
]
}
}
},
{
"source": {
"title": "Featured product selections",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
}
selections(first: 10) {
nodes {
product {
id
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"title": "Layered spring collection",
"sources": [
{
"source": {
"title": "Products tagged spring",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
}
]
}
}
},
{
"source": {
"title": "Featured product selections",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
}
selections(first: 10) {
nodes {
product {
id
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"title": "Layered spring collection",
"sources": [
{
"source": {
"title": "Products tagged spring",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
}
]
}
}
},
{
"source": {
"title": "Featured product selections",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/unstable/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
}
selections(first: 10) {
nodes {
product {
id
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"title": "Layered spring collection",
"sources": [
{
"source": {
"title": "Products tagged spring",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
}
]
}
}
},
{
"source": {
"title": "Featured product selections",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001401",
"title": "Layered spring collection",
"sources": [
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/1047893286",
"title": "Products tagged spring",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"__typename": "CollectionSourceInclusionConditionProductTag"
}
],
"selections": {
"nodes": []
}
}
},
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/1047893287",
"title": "Featured product selections",
"inclusion": {
"matchType": null,
"conditions": [],
"selections": {
"nodes": [
{
"product": {
"id": "gid://shopify/Product/20995642"
}
}
]
}
}
}
]
},
"userErrors": []
}
}
Create a collection with selected variants
Description
Create a variant-targeted collection source by selecting specific product variants. Pass
`targetType: VARIANTS` and provide `variantIds` with each selected product.
Query
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"title": "Selected variants",
"sources": [
{
"source": {
"title": "Selected variants source",
"targetType": "VARIANTS",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642",
"variantIds": [
"gid://shopify/ProductVariant/30322695"
]
}
]
}
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionCreate($collection: CollectionCreateInput!) { collectionCreate(collection: $collection) { collection { id title sources { __typename id title ... on CollectionConditionsSource { inclusion { selections(first: 10) { nodes { product { id title } variantIds } } } } } } userErrors { field message } } }",
"variables": {
"collection": {
"title": "Selected variants",
"sources": [
{
"source": {
"title": "Selected variants source",
"targetType": "VARIANTS",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642",
"variantIds": [
"gid://shopify/ProductVariant/30322695"
]
}
]
}
}
}
]
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"title": "Selected variants",
"sources": [
{
"source": {
"title": "Selected variants source",
"targetType": "VARIANTS",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642",
"variantIds": [
"gid://shopify/ProductVariant/30322695"
]
}
]
}
}
}
]
}
},
},
);
const json = await response.json();
return json.data;
}
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
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"title": "Selected variants",
"sources": [
{
"source": {
"title": "Selected variants source",
"targetType": "VARIANTS",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642",
"variantIds": [
"gid://shopify/ProductVariant/30322695"
]
}
]
}
}
}
]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"title": "Selected variants",
"sources": [
{
"source": {
"title": "Selected variants source",
"targetType": "VARIANTS",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642",
"variantIds": [
"gid://shopify/ProductVariant/30322695"
]
}
]
}
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"title": "Selected variants",
"sources": [
{
"source": {
"title": "Selected variants source",
"targetType": "VARIANTS",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642",
"variantIds": [
"gid://shopify/ProductVariant/30322695"
]
}
]
}
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/unstable/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"title": "Selected variants",
"sources": [
{
"source": {
"title": "Selected variants source",
"targetType": "VARIANTS",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/20995642",
"variantIds": [
"gid://shopify/ProductVariant/30322695"
]
}
]
}
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001441",
"title": "Selected variants",
"sources": [
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/1047893296",
"title": "Selected variants source",
"inclusion": {
"selections": {
"nodes": [
{
"product": {
"id": "gid://shopify/Product/20995642",
"title": "Element"
},
"variantIds": [
"gid://shopify/ProductVariant/30322695"
]
}
]
}
}
}
]
},
"userErrors": []
}
}
Create a collection with sources
Description
Create a collection that uses sources to include products. This example demonstrates how to
configure collection details, SEO metadata, metafields, an image, and product membership through
source conditions and manual product selections.
Query
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
templateSuffix
image {
url
altText
}
seo {
title
description
}
metafields(first: 10) {
nodes {
namespace
key
value
}
}
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductTag {
tagRelation: relation
values
matchType
}
... on CollectionSourceInclusionConditionProductTitle {
titleRelation: relation
values
matchType
}
}
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"title": "Spring styles",
"descriptionHtml": "Products for the <strong>spring</strong> season.",
"handle": "spring-styles",
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/d5e5e795-b6cf-4c42-88ae-d3e18576aa2b/test_file.txt",
"altText": "Spring collection image"
},
"seo": {
"title": "Spring styles collection",
"description": "Browse spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sources": [
{
"source": {
"title": "Spring source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
},
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shirt"
],
"matchType": "ANY"
}
}
],
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionCreate($collection: CollectionCreateInput!) { collectionCreate(collection: $collection) { collection { id title descriptionHtml handle sortOrder templateSuffix image { url altText } seo { title description } metafields(first: 10) { nodes { namespace key value } } sources { __typename id title ... on CollectionConditionsSource { inclusion { matchType conditions { __typename id ... on CollectionSourceInclusionConditionProductTag { tagRelation: relation values matchType } ... on CollectionSourceInclusionConditionProductTitle { titleRelation: relation values matchType } } selections(first: 10) { nodes { product { id title } variantIds } } } } } } userErrors { field message } } }",
"variables": {
"collection": {
"title": "Spring styles",
"descriptionHtml": "Products for the <strong>spring</strong> season.",
"handle": "spring-styles",
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/d5e5e795-b6cf-4c42-88ae-d3e18576aa2b/test_file.txt",
"altText": "Spring collection image"
},
"seo": {
"title": "Spring styles collection",
"description": "Browse spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sources": [
{
"source": {
"title": "Spring source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
},
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shirt"
],
"matchType": "ANY"
}
}
],
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
templateSuffix
image {
url
altText
}
seo {
title
description
}
metafields(first: 10) {
nodes {
namespace
key
value
}
}
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductTag {
tagRelation: relation
values
matchType
}
... on CollectionSourceInclusionConditionProductTitle {
titleRelation: relation
values
matchType
}
}
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"title": "Spring styles",
"descriptionHtml": "Products for the <strong>spring</strong> season.",
"handle": "spring-styles",
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/d5e5e795-b6cf-4c42-88ae-d3e18576aa2b/test_file.txt",
"altText": "Spring collection image"
},
"seo": {
"title": "Spring styles collection",
"description": "Browse spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sources": [
{
"source": {
"title": "Spring source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
},
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shirt"
],
"matchType": "ANY"
}
}
],
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
},
},
);
const json = await response.json();
return json.data;
}
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
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
templateSuffix
image {
url
altText
}
seo {
title
description
}
metafields(first: 10) {
nodes {
namespace
key
value
}
}
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductTag {
tagRelation: relation
values
matchType
}
... on CollectionSourceInclusionConditionProductTitle {
titleRelation: relation
values
matchType
}
}
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"title": "Spring styles",
"descriptionHtml": "Products for the <strong>spring</strong> season.",
"handle": "spring-styles",
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/d5e5e795-b6cf-4c42-88ae-d3e18576aa2b/test_file.txt",
"altText": "Spring collection image"
},
"seo": {
"title": "Spring styles collection",
"description": "Browse spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sources": [
{
"source": {
"title": "Spring source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
},
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shirt"
],
"matchType": "ANY"
}
}
],
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
templateSuffix
image {
url
altText
}
seo {
title
description
}
metafields(first: 10) {
nodes {
namespace
key
value
}
}
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductTag {
tagRelation: relation
values
matchType
}
... on CollectionSourceInclusionConditionProductTitle {
titleRelation: relation
values
matchType
}
}
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"title": "Spring styles",
"descriptionHtml": "Products for the <strong>spring</strong> season.",
"handle": "spring-styles",
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/d5e5e795-b6cf-4c42-88ae-d3e18576aa2b/test_file.txt",
"altText": "Spring collection image"
},
"seo": {
"title": "Spring styles collection",
"description": "Browse spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sources": [
{
"source": {
"title": "Spring source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
},
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shirt"
],
"matchType": "ANY"
}
}
],
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
templateSuffix
image {
url
altText
}
seo {
title
description
}
metafields(first: 10) {
nodes {
namespace
key
value
}
}
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductTag {
tagRelation: relation
values
matchType
}
... on CollectionSourceInclusionConditionProductTitle {
titleRelation: relation
values
matchType
}
}
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"title": "Spring styles",
"descriptionHtml": "Products for the <strong>spring</strong> season.",
"handle": "spring-styles",
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/d5e5e795-b6cf-4c42-88ae-d3e18576aa2b/test_file.txt",
"altText": "Spring collection image"
},
"seo": {
"title": "Spring styles collection",
"description": "Browse spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sources": [
{
"source": {
"title": "Spring source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
},
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shirt"
],
"matchType": "ANY"
}
}
],
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/unstable/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
templateSuffix
image {
url
altText
}
seo {
title
description
}
metafields(first: 10) {
nodes {
namespace
key
value
}
}
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductTag {
tagRelation: relation
values
matchType
}
... on CollectionSourceInclusionConditionProductTitle {
titleRelation: relation
values
matchType
}
}
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"title": "Spring styles",
"descriptionHtml": "Products for the <strong>spring</strong> season.",
"handle": "spring-styles",
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/d5e5e795-b6cf-4c42-88ae-d3e18576aa2b/test_file.txt",
"altText": "Spring collection image"
},
"seo": {
"title": "Spring styles collection",
"description": "Browse spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sources": [
{
"source": {
"title": "Spring source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
},
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shirt"
],
"matchType": "ANY"
}
}
],
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001409",
"title": "Spring styles",
"descriptionHtml": "Products for the <strong>spring</strong> season.",
"handle": "spring-styles",
"sortOrder": "MANUAL",
"templateSuffix": "spring",
"image": {
"url": "https://cdn.shopify.com/s/files/1/2637/1970/collections/test_file.jpg?v=1781273011",
"altText": "Spring collection image"
},
"seo": {
"title": "Spring styles collection",
"description": "Browse spring products."
},
"metafields": {
"nodes": [
{
"namespace": "global",
"key": "title_tag",
"value": "Spring styles collection"
},
{
"namespace": "global",
"key": "description_tag",
"value": "Browse spring products."
},
{
"namespace": "custom",
"key": "season",
"value": "spring"
}
]
},
"sources": [
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/1047893291",
"title": "Spring source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"__typename": "CollectionSourceInclusionConditionProductTag",
"id": "gid://shopify/CollectionSourceInclusionConditionProductTag/977278325",
"tagRelation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
},
{
"__typename": "CollectionSourceInclusionConditionProductTitle",
"id": "gid://shopify/CollectionSourceInclusionConditionProductTitle/977278326",
"titleRelation": "CONTAINS",
"values": [
"shirt"
],
"matchType": "ANY"
}
],
"selections": {
"nodes": [
{
"product": {
"id": "gid://shopify/Product/20995642",
"title": "Element"
},
"variantIds": null
}
]
}
}
}
]
},
"userErrors": []
}
}
Create a custom collection
Description
Create a [custom collection](https://help.shopify.com/manual/products/collections/manual-shopify-collection)
by defining the collection's title, description, handle,
and associated products. The response returns detailed information about the newly
created collection, including its ID, title, description, update timestamp, handle,
an image, and a list of associated products.
Query
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
title
descriptionHtml
updatedAt
handle
image {
id
height
width
url
}
products(first: 10) {
nodes {
id
featuredMedia {
id
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"input": {
"title": "New Custom Collection",
"descriptionHtml": "This is a custom collection.",
"handle": "custom-collection",
"products": [
"gid://shopify/Product/20995642"
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionCreate($input: CollectionInput!) { collectionCreate(input: $input) { collection { id title descriptionHtml updatedAt handle image { id height width url } products(first: 10) { nodes { id featuredMedia { id } } } } userErrors { field message } } }",
"variables": {
"input": {
"title": "New Custom Collection",
"descriptionHtml": "This is a custom collection.",
"handle": "custom-collection",
"products": [
"gid://shopify/Product/20995642"
]
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
title
descriptionHtml
updatedAt
handle
image {
id
height
width
url
}
products(first: 10) {
nodes {
id
featuredMedia {
id
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"input": {
"title": "New Custom Collection",
"descriptionHtml": "This is a custom collection.",
"handle": "custom-collection",
"products": [
"gid://shopify/Product/20995642"
]
}
},
},
);
const json = await response.json();
return json.data;
}
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
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
title
descriptionHtml
updatedAt
handle
image {
id
height
width
url
}
products(first: 10) {
nodes {
id
featuredMedia {
id
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"input": {
"title": "New Custom Collection",
"descriptionHtml": "This is a custom collection.",
"handle": "custom-collection",
"products": [
"gid://shopify/Product/20995642"
]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
title
descriptionHtml
updatedAt
handle
image {
id
height
width
url
}
products(first: 10) {
nodes {
id
featuredMedia {
id
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"input": {
"title": "New Custom Collection",
"descriptionHtml": "This is a custom collection.",
"handle": "custom-collection",
"products": [
"gid://shopify/Product/20995642"
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
title
descriptionHtml
updatedAt
handle
image {
id
height
width
url
}
products(first: 10) {
nodes {
id
featuredMedia {
id
}
}
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"input": {
"title": "New Custom Collection",
"descriptionHtml": "This is a custom collection.",
"handle": "custom-collection",
"products": [
"gid://shopify/Product/20995642"
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/unstable/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
title
descriptionHtml
updatedAt
handle
image {
id
height
width
url
}
products(first: 10) {
nodes {
id
featuredMedia {
id
}
}
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"input": {
"title": "New Custom Collection",
"descriptionHtml": "This is a custom collection.",
"handle": "custom-collection",
"products": [
"gid://shopify/Product/20995642"
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001436",
"title": "New Custom Collection",
"descriptionHtml": "This is a custom collection.",
"updatedAt": "2026-06-12T14:03:36Z",
"handle": "custom-collection",
"image": null,
"products": {
"nodes": [
{
"id": "gid://shopify/Product/20995642",
"featuredMedia": {
"id": "gid://shopify/MediaImage/730211239"
}
}
]
}
},
"userErrors": []
}
}
Create a new metafield on a new collection
Description
Create a new metafield `my_field.subtitle` on a new
collection.
Alternatively, refer to the
[`metafieldsSet`](https://shopify.dev/docs/api/admin-graphql/latest/mutations/metafieldsset) mutation
to create and update metafields on collection resources.
Query
mutation createCollectionMetafields($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
Variables
{
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
],
"title": "Spring Styles"
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation createCollectionMetafields($input: CollectionInput!) { collectionCreate(input: $input) { collection { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }",
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
],
"title": "Spring Styles"
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation createCollectionMetafields($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
{
variables: {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
],
"title": "Spring Styles"
}
},
},
);
const json = await response.json();
return json.data;
}
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
mutation createCollectionMetafields($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
QUERY
variables = {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
],
"title": "Spring Styles"
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation createCollectionMetafields($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
],
"title": "Spring Styles"
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation createCollectionMetafields($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}' \
--variables \
'{
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
],
"title": "Spring Styles"
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/unstable/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation createCollectionMetafields($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
`,
variables: {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
],
"title": "Spring Styles"
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001315",
"metafields": {
"edges": [
{
"node": {
"id": "gid://shopify/Metafield/1069228935",
"namespace": "my_field",
"key": "subtitle",
"value": "Bold Colors"
}
}
]
}
},
"userErrors": []
}
}
Create a smart collection
Description
Create a [smart collection](https://help.shopify.com/manual/products/collections/smart-collections),
specifically tailored for a store's shoe collection. The response returns the details of the newly
created collection, including its ID, title, description, handle, sort order, and the defined rule set
in the [collection's conditions](https://help.shopify.com/manual/products/collections/smart-collections/conditions).
Query
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
descriptionHtml
handle
sortOrder
ruleSet {
appliedDisjunctively
rules {
column
relation
condition
}
}
}
}
}
Variables
{
"input": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": {
"column": "TITLE",
"relation": "CONTAINS",
"condition": "shoe"
}
}
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionCreate($input: CollectionInput!) { collectionCreate(input: $input) { userErrors { field message } collection { id title descriptionHtml handle sortOrder ruleSet { appliedDisjunctively rules { column relation condition } } } } }",
"variables": {
"input": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": {
"column": "TITLE",
"relation": "CONTAINS",
"condition": "shoe"
}
}
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
descriptionHtml
handle
sortOrder
ruleSet {
appliedDisjunctively
rules {
column
relation
condition
}
}
}
}
}`,
{
variables: {
"input": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": {
"column": "TITLE",
"relation": "CONTAINS",
"condition": "shoe"
}
}
}
},
},
);
const json = await response.json();
return json.data;
}
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
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
descriptionHtml
handle
sortOrder
ruleSet {
appliedDisjunctively
rules {
column
relation
condition
}
}
}
}
}
QUERY
variables = {
"input": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": {
"column": "TITLE",
"relation": "CONTAINS",
"condition": "shoe"
}
}
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
descriptionHtml
handle
sortOrder
ruleSet {
appliedDisjunctively
rules {
column
relation
condition
}
}
}
}
}`,
"variables": {
"input": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": {
"column": "TITLE",
"relation": "CONTAINS",
"condition": "shoe"
}
}
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
descriptionHtml
handle
sortOrder
ruleSet {
appliedDisjunctively
rules {
column
relation
condition
}
}
}
}
}' \
--variables \
'{
"input": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": {
"column": "TITLE",
"relation": "CONTAINS",
"condition": "shoe"
}
}
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/unstable/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
descriptionHtml
handle
sortOrder
ruleSet {
appliedDisjunctively
rules {
column
relation
condition
}
}
}
}
}
`,
variables: {
"input": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": {
"column": "TITLE",
"relation": "CONTAINS",
"condition": "shoe"
}
}
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"userErrors": [],
"collection": {
"id": "gid://shopify/Collection/1063001438",
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"handle": "our-entire-shoe-collection",
"sortOrder": "MOST_RELEVANT",
"ruleSet": {
"appliedDisjunctively": false,
"rules": [
{
"column": "TITLE",
"relation": "CONTAINS",
"condition": "shoe"
}
]
}
}
}
}
Create a smart collection with metafield definition conditions
Description
Create a [smart collection](https://help.shopify.com/manual/products/collections/smart-collections)
that contains all products with the specific product and variant
[metafield definition conditions](https://shopify.dev/docs/apps/build/custom-data/metafields/definitions).
The collection includes all products that have the product metafield value
`leather` and the variant metafield value `true`.
Query
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
descriptionHtml
handle
sortOrder
ruleSet {
appliedDisjunctively
rules {
column
relation
condition
conditionObject {
... on CollectionRuleMetafieldCondition {
metafieldDefinition {
id
name
type {
name
}
ownerType
}
}
}
}
}
}
}
}
Variables
{
"input": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": [
{
"column": "PRODUCT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "leather",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456136"
},
{
"column": "VARIANT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "true",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456137"
}
]
}
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionCreate($input: CollectionInput!) { collectionCreate(input: $input) { userErrors { field message } collection { id title descriptionHtml handle sortOrder ruleSet { appliedDisjunctively rules { column relation condition conditionObject { ... on CollectionRuleMetafieldCondition { metafieldDefinition { id name type { name } ownerType } } } } } } } }",
"variables": {
"input": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": [
{
"column": "PRODUCT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "leather",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456136"
},
{
"column": "VARIANT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "true",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456137"
}
]
}
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
descriptionHtml
handle
sortOrder
ruleSet {
appliedDisjunctively
rules {
column
relation
condition
conditionObject {
... on CollectionRuleMetafieldCondition {
metafieldDefinition {
id
name
type {
name
}
ownerType
}
}
}
}
}
}
}
}`,
{
variables: {
"input": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": [
{
"column": "PRODUCT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "leather",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456136"
},
{
"column": "VARIANT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "true",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456137"
}
]
}
}
},
},
);
const json = await response.json();
return json.data;
}
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
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
descriptionHtml
handle
sortOrder
ruleSet {
appliedDisjunctively
rules {
column
relation
condition
conditionObject {
... on CollectionRuleMetafieldCondition {
metafieldDefinition {
id
name
type {
name
}
ownerType
}
}
}
}
}
}
}
}
QUERY
variables = {
"input": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": [
{
"column": "PRODUCT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "leather",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456136"
},
{
"column": "VARIANT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "true",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456137"
}
]
}
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
descriptionHtml
handle
sortOrder
ruleSet {
appliedDisjunctively
rules {
column
relation
condition
conditionObject {
... on CollectionRuleMetafieldCondition {
metafieldDefinition {
id
name
type {
name
}
ownerType
}
}
}
}
}
}
}
}`,
"variables": {
"input": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": [
{
"column": "PRODUCT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "leather",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456136"
},
{
"column": "VARIANT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "true",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456137"
}
]
}
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
descriptionHtml
handle
sortOrder
ruleSet {
appliedDisjunctively
rules {
column
relation
condition
conditionObject {
... on CollectionRuleMetafieldCondition {
metafieldDefinition {
id
name
type {
name
}
ownerType
}
}
}
}
}
}
}
}' \
--variables \
'{
"input": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": [
{
"column": "PRODUCT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "leather",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456136"
},
{
"column": "VARIANT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "true",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456137"
}
]
}
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/unstable/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($input: CollectionInput!) {
collectionCreate(input: $input) {
userErrors {
field
message
}
collection {
id
title
descriptionHtml
handle
sortOrder
ruleSet {
appliedDisjunctively
rules {
column
relation
condition
conditionObject {
... on CollectionRuleMetafieldCondition {
metafieldDefinition {
id
name
type {
name
}
ownerType
}
}
}
}
}
}
}
}
`,
variables: {
"input": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"ruleSet": {
"appliedDisjunctively": false,
"rules": [
{
"column": "PRODUCT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "leather",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456136"
},
{
"column": "VARIANT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "true",
"conditionObjectId": "gid://shopify/MetafieldDefinition/1071456137"
}
]
}
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"userErrors": [],
"collection": {
"id": "gid://shopify/Collection/1063001433",
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"handle": "our-entire-leather-collection",
"sortOrder": "MOST_RELEVANT",
"ruleSet": {
"appliedDisjunctively": false,
"rules": [
{
"column": "PRODUCT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "leather",
"conditionObject": {
"metafieldDefinition": {
"id": "gid://shopify/MetafieldDefinition/1071456136",
"name": "Material",
"type": {
"name": "single_line_text_field"
},
"ownerType": "PRODUCT"
}
}
},
{
"column": "VARIANT_METAFIELD_DEFINITION",
"relation": "EQUALS",
"condition": "true",
"conditionObject": {
"metafieldDefinition": {
"id": "gid://shopify/MetafieldDefinition/1071456137",
"name": "Imported",
"type": {
"name": "boolean"
},
"ownerType": "PRODUCTVARIANT"
}
}
}
]
}
}
}
}