Create a collection from an existing source
Description
Create a collection by linking an existing shareable source. Use `shareableSource` 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": [
{
"shareableSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-10/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": [
{
"shareableSource": {
"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": [
{
"shareableSource": {
"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": [
{
"shareableSource": {
"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": [
{
"shareableSource": {
"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": [
{
"shareableSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2026-10/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": [
{
"shareableSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001311",
"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 other collections
Description
Create a collection with a sub-collection source. The new collection includes products from
one or more collections through the `subCollections` source target.
Query
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionSubCollectionsSource {
collections {
id
title
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollections": {
"title": "Featured products source",
"description": "Products from featured and sale collections.",
"collectionIds": [
"gid://shopify/Collection/1007901140",
"gid://shopify/Collection/711838235"
]
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-10/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 CollectionSubCollectionsSource { collections { id title } } } } userErrors { field message } } }",
"variables": {
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollections": {
"title": "Featured products source",
"description": "Products from featured and sale collections.",
"collectionIds": [
"gid://shopify/Collection/1007901140",
"gid://shopify/Collection/711838235"
]
}
}
]
}
}
}'
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 CollectionSubCollectionsSource {
collections {
id
title
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollections": {
"title": "Featured products source",
"description": "Products from featured and sale collections.",
"collectionIds": [
"gid://shopify/Collection/1007901140",
"gid://shopify/Collection/711838235"
]
}
}
]
}
},
},
);
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 CollectionSubCollectionsSource {
collections {
id
title
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollections": {
"title": "Featured products source",
"description": "Products from featured and sale collections.",
"collectionIds": [
"gid://shopify/Collection/1007901140",
"gid://shopify/Collection/711838235"
]
}
}
]
}
}
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 CollectionSubCollectionsSource {
collections {
id
title
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollections": {
"title": "Featured products source",
"description": "Products from featured and sale collections.",
"collectionIds": [
"gid://shopify/Collection/1007901140",
"gid://shopify/Collection/711838235"
]
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionSubCollectionsSource {
collections {
id
title
}
}
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollections": {
"title": "Featured products source",
"description": "Products from featured and sale collections.",
"collectionIds": [
"gid://shopify/Collection/1007901140",
"gid://shopify/Collection/711838235"
]
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2026-10/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
... on CollectionSubCollectionsSource {
collections {
id
title
}
}
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"title": "Featured spring products",
"sources": [
{
"subCollections": {
"title": "Featured products source",
"description": "Products from featured and sale collections.",
"collectionIds": [
"gid://shopify/Collection/1007901140",
"gid://shopify/Collection/711838235"
]
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001311",
"title": "Featured spring products",
"sources": [
{
"__typename": "CollectionSubCollectionsSource",
"id": "gid://shopify/CollectionSubCollectionsSource/1047893119",
"title": "Featured products source",
"collections": [
{
"id": "gid://shopify/Collection/1007901140",
"title": "Featured items"
},
{
"id": "gid://shopify/Collection/711838235",
"title": "On Sale!"
}
]
}
]
},
"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($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
image {
url
altText
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"title": "Summer collection",
"image": {
"src": "tmp/26371970/collections/6ad99b2f-d1ec-49e9-86d8-b1db0333fdac/test_file.txt",
"altText": "Summer collection banner"
}
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-10/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 image { url altText } } userErrors { field message } } }",
"variables": {
"collection": {
"title": "Summer collection",
"image": {
"src": "tmp/26371970/collections/6ad99b2f-d1ec-49e9-86d8-b1db0333fdac/test_file.txt",
"altText": "Summer collection banner"
}
}
}
}'
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
image {
url
altText
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"title": "Summer collection",
"image": {
"src": "tmp/26371970/collections/6ad99b2f-d1ec-49e9-86d8-b1db0333fdac/test_file.txt",
"altText": "Summer collection banner"
}
}
},
},
);
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
image {
url
altText
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"title": "Summer collection",
"image": {
"src": "tmp/26371970/collections/6ad99b2f-d1ec-49e9-86d8-b1db0333fdac/test_file.txt",
"altText": "Summer collection banner"
}
}
}
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
image {
url
altText
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"title": "Summer collection",
"image": {
"src": "tmp/26371970/collections/6ad99b2f-d1ec-49e9-86d8-b1db0333fdac/test_file.txt",
"altText": "Summer collection banner"
}
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
image {
url
altText
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"title": "Summer collection",
"image": {
"src": "tmp/26371970/collections/6ad99b2f-d1ec-49e9-86d8-b1db0333fdac/test_file.txt",
"altText": "Summer collection banner"
}
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2026-10/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
image {
url
altText
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"title": "Summer collection",
"image": {
"src": "tmp/26371970/collections/6ad99b2f-d1ec-49e9-86d8-b1db0333fdac/test_file.txt",
"altText": "Summer collection banner"
}
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001463",
"title": "Summer collection",
"image": {
"url": "https://cdn.shopify.com/s/files/1/2637/1970/collections/test_file.jpg?v=1780000000",
"altText": "Summer collection banner"
}
},
"userErrors": []
}
}
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/2026-10/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/2026-10/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/2026-10/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/2026-10/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/2026-10/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/2026-10/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, sort order, and the products that you pick
by hand. The collection has one source with `inclusion.selections` that list the products and no
conditions. The response returns the newly created collection, including its ID, title, description,
handle, sort order, its source with the selected products, and the first products in the collection,
sorted by title.
Query
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
selections(first: 10) {
nodes {
product {
id
title
}
}
}
}
}
}
products(first: 10) {
nodes {
id
title
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"title": "Staff picks",
"descriptionHtml": "Products our staff recommend this season.",
"handle": "staff-picks",
"sortOrder": "ALPHA_ASC",
"sources": [
{
"source": {
"title": "Hand-picked products",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/121709582"
},
{
"productId": "gid://shopify/Product/910489600"
}
]
}
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-10/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 sources { __typename id title ... on CollectionConditionsSource { inclusion { selections(first: 10) { nodes { product { id title } } } } } } products(first: 10) { nodes { id title } } } userErrors { field message } } }",
"variables": {
"collection": {
"title": "Staff picks",
"descriptionHtml": "Products our staff recommend this season.",
"handle": "staff-picks",
"sortOrder": "ALPHA_ASC",
"sources": [
{
"source": {
"title": "Hand-picked products",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/121709582"
},
{
"productId": "gid://shopify/Product/910489600"
}
]
}
}
}
]
}
}
}'
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
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
selections(first: 10) {
nodes {
product {
id
title
}
}
}
}
}
}
products(first: 10) {
nodes {
id
title
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"title": "Staff picks",
"descriptionHtml": "Products our staff recommend this season.",
"handle": "staff-picks",
"sortOrder": "ALPHA_ASC",
"sources": [
{
"source": {
"title": "Hand-picked products",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/121709582"
},
{
"productId": "gid://shopify/Product/910489600"
}
]
}
}
}
]
}
},
},
);
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
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
selections(first: 10) {
nodes {
product {
id
title
}
}
}
}
}
}
products(first: 10) {
nodes {
id
title
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"title": "Staff picks",
"descriptionHtml": "Products our staff recommend this season.",
"handle": "staff-picks",
"sortOrder": "ALPHA_ASC",
"sources": [
{
"source": {
"title": "Hand-picked products",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/121709582"
},
{
"productId": "gid://shopify/Product/910489600"
}
]
}
}
}
]
}
}
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
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
selections(first: 10) {
nodes {
product {
id
title
}
}
}
}
}
}
products(first: 10) {
nodes {
id
title
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"title": "Staff picks",
"descriptionHtml": "Products our staff recommend this season.",
"handle": "staff-picks",
"sortOrder": "ALPHA_ASC",
"sources": [
{
"source": {
"title": "Hand-picked products",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/121709582"
},
{
"productId": "gid://shopify/Product/910489600"
}
]
}
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
selections(first: 10) {
nodes {
product {
id
title
}
}
}
}
}
}
products(first: 10) {
nodes {
id
title
}
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"title": "Staff picks",
"descriptionHtml": "Products our staff recommend this season.",
"handle": "staff-picks",
"sortOrder": "ALPHA_ASC",
"sources": [
{
"source": {
"title": "Hand-picked products",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/121709582"
},
{
"productId": "gid://shopify/Product/910489600"
}
]
}
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2026-10/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
selections(first: 10) {
nodes {
product {
id
title
}
}
}
}
}
}
products(first: 10) {
nodes {
id
title
}
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"title": "Staff picks",
"descriptionHtml": "Products our staff recommend this season.",
"handle": "staff-picks",
"sortOrder": "ALPHA_ASC",
"sources": [
{
"source": {
"title": "Hand-picked products",
"inclusion": {
"selections": [
{
"productId": "gid://shopify/Product/121709582"
},
{
"productId": "gid://shopify/Product/910489600"
}
]
}
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001462",
"title": "Staff picks",
"descriptionHtml": "Products our staff recommend this season.",
"handle": "staff-picks",
"sortOrder": "ALPHA_ASC",
"sources": [
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/482866111",
"title": "Hand-picked products",
"inclusion": {
"selections": {
"nodes": [
{
"product": {
"id": "gid://shopify/Product/121709582",
"title": "Boots"
}
},
{
"product": {
"id": "gid://shopify/Product/910489600",
"title": "Crafty Shoes"
}
}
]
}
}
}
],
"products": {
"nodes": [
{
"id": "gid://shopify/Product/121709582",
"title": "Boots"
},
{
"id": "gid://shopify/Product/910489600",
"title": "Crafty Shoes"
}
]
}
},
"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($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
Variables
{
"collection": {
"title": "Spring Styles",
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation createCollectionMetafields($collection: CollectionCreateInput!) { collectionCreate(collection: $collection) { collection { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }",
"variables": {
"collection": {
"title": "Spring Styles",
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
]
}
}
}'
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($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
{
variables: {
"collection": {
"title": "Spring Styles",
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
]
}
},
},
);
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($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
QUERY
variables = {
"collection": {
"title": "Spring Styles",
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
]
}
}
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($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
"variables": {
"collection": {
"title": "Spring Styles",
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation createCollectionMetafields($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}' \
--variables \
'{
"collection": {
"title": "Spring Styles",
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2026-10/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation createCollectionMetafields($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
`,
variables: {
"collection": {
"title": "Spring Styles",
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
]
}
},
}),
});
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 collection's source has a `productTitle`
condition, so the collection includes every product whose title contains `shoe`. The response returns
the details of the newly created collection, including its ID, title, description, handle, sort order,
and its source with the
[collection's conditions](https://help.shopify.com/manual/products/collections/smart-collections/conditions).
Query
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductTitle {
relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"sources": [
{
"source": {
"title": "Products with shoe in the title",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shoe"
],
"matchType": "ANY"
}
}
]
}
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-10/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 sources { __typename id title ... on CollectionConditionsSource { inclusion { matchType conditions { __typename id ... on CollectionSourceInclusionConditionProductTitle { relation values matchType } } } } } } userErrors { field message } } }",
"variables": {
"collection": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"sources": [
{
"source": {
"title": "Products with shoe in the title",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shoe"
],
"matchType": "ANY"
}
}
]
}
}
}
]
}
}
}'
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
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductTitle {
relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"sources": [
{
"source": {
"title": "Products with shoe in the title",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shoe"
],
"matchType": "ANY"
}
}
]
}
}
}
]
}
},
},
);
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
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductTitle {
relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"sources": [
{
"source": {
"title": "Products with shoe in the title",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shoe"
],
"matchType": "ANY"
}
}
]
}
}
}
]
}
}
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
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductTitle {
relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"sources": [
{
"source": {
"title": "Products with shoe in the title",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shoe"
],
"matchType": "ANY"
}
}
]
}
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductTitle {
relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"sources": [
{
"source": {
"title": "Products with shoe in the title",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shoe"
],
"matchType": "ANY"
}
}
]
}
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2026-10/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductTitle {
relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"sources": [
{
"source": {
"title": "Products with shoe in the title",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTitle": {
"relation": "CONTAINS",
"values": [
"shoe"
],
"matchType": "ANY"
}
}
]
}
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001461",
"title": "Our entire shoe collection",
"descriptionHtml": "View <b>every</b> shoe available in our store.",
"handle": "our-entire-shoe-collection",
"sortOrder": "MOST_RELEVANT",
"sources": [
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/482866110",
"title": "Products with shoe in the title",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"__typename": "CollectionSourceInclusionConditionProductTitle",
"id": "gid://shopify/CollectionSourceInclusionConditionProductTitle/937184302",
"relation": "CONTAINS",
"values": [
"shoe"
],
"matchType": "ANY"
}
]
}
}
]
},
"userErrors": []
}
}
Create a smart collection with metafield definition conditions
Description
Create a [smart collection](https://help.shopify.com/manual/products/collections/smart-collections)
whose source uses
[metafield definition conditions](https://shopify.dev/docs/apps/build/custom-data/metafields/definitions).
The source combines a `metafieldString` condition on a product metafield definition and a
`metafieldBoolean` condition on a variant metafield definition. Because the source's `matchType` is
`ALL`, the collection includes products that have the product metafield value `leather` and the
variant metafield value `true`.
Query
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionMetafieldString {
values
matchType
definition {
id
name
type {
name
}
ownerType
}
}
... on CollectionSourceInclusionConditionMetafieldBoolean {
value
definition {
id
name
type {
name
}
ownerType
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"sources": [
{
"source": {
"title": "Leather products with imported variants",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"metafieldString": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456136",
"relation": "EQUALS",
"values": [
"leather"
],
"matchType": "ANY"
}
},
{
"metafieldBoolean": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456137",
"relation": "EQUALS",
"value": true
}
}
]
}
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-10/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 sources { __typename id title ... on CollectionConditionsSource { inclusion { matchType conditions { __typename id ... on CollectionSourceInclusionConditionMetafieldString { values matchType definition { id name type { name } ownerType } } ... on CollectionSourceInclusionConditionMetafieldBoolean { value definition { id name type { name } ownerType } } } } } } } userErrors { field message } } }",
"variables": {
"collection": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"sources": [
{
"source": {
"title": "Leather products with imported variants",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"metafieldString": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456136",
"relation": "EQUALS",
"values": [
"leather"
],
"matchType": "ANY"
}
},
{
"metafieldBoolean": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456137",
"relation": "EQUALS",
"value": true
}
}
]
}
}
}
]
}
}
}'
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
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionMetafieldString {
values
matchType
definition {
id
name
type {
name
}
ownerType
}
}
... on CollectionSourceInclusionConditionMetafieldBoolean {
value
definition {
id
name
type {
name
}
ownerType
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"sources": [
{
"source": {
"title": "Leather products with imported variants",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"metafieldString": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456136",
"relation": "EQUALS",
"values": [
"leather"
],
"matchType": "ANY"
}
},
{
"metafieldBoolean": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456137",
"relation": "EQUALS",
"value": true
}
}
]
}
}
}
]
}
},
},
);
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
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionMetafieldString {
values
matchType
definition {
id
name
type {
name
}
ownerType
}
}
... on CollectionSourceInclusionConditionMetafieldBoolean {
value
definition {
id
name
type {
name
}
ownerType
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"sources": [
{
"source": {
"title": "Leather products with imported variants",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"metafieldString": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456136",
"relation": "EQUALS",
"values": [
"leather"
],
"matchType": "ANY"
}
},
{
"metafieldBoolean": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456137",
"relation": "EQUALS",
"value": true
}
}
]
}
}
}
]
}
}
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
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionMetafieldString {
values
matchType
definition {
id
name
type {
name
}
ownerType
}
}
... on CollectionSourceInclusionConditionMetafieldBoolean {
value
definition {
id
name
type {
name
}
ownerType
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"sources": [
{
"source": {
"title": "Leather products with imported variants",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"metafieldString": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456136",
"relation": "EQUALS",
"values": [
"leather"
],
"matchType": "ANY"
}
},
{
"metafieldBoolean": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456137",
"relation": "EQUALS",
"value": true
}
}
]
}
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionMetafieldString {
values
matchType
definition {
id
name
type {
name
}
ownerType
}
}
... on CollectionSourceInclusionConditionMetafieldBoolean {
value
definition {
id
name
type {
name
}
ownerType
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"sources": [
{
"source": {
"title": "Leather products with imported variants",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"metafieldString": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456136",
"relation": "EQUALS",
"values": [
"leather"
],
"matchType": "ANY"
}
},
{
"metafieldBoolean": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456137",
"relation": "EQUALS",
"value": true
}
}
]
}
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2026-10/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionCreate($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection {
id
title
descriptionHtml
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionMetafieldString {
values
matchType
definition {
id
name
type {
name
}
ownerType
}
}
... on CollectionSourceInclusionConditionMetafieldBoolean {
value
definition {
id
name
type {
name
}
ownerType
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"sources": [
{
"source": {
"title": "Leather products with imported variants",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"metafieldString": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456136",
"relation": "EQUALS",
"values": [
"leather"
],
"matchType": "ANY"
}
},
{
"metafieldBoolean": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456137",
"relation": "EQUALS",
"value": true
}
}
]
}
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001462",
"title": "Our entire leather collection",
"descriptionHtml": "Check out our leather products.",
"handle": "our-entire-leather-collection",
"sortOrder": "MOST_RELEVANT",
"sources": [
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/482866111",
"title": "Leather products with imported variants",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"__typename": "CollectionSourceInclusionConditionMetafieldString",
"id": "gid://shopify/CollectionSourceInclusionConditionMetafieldString/937184303",
"values": [
"leather"
],
"matchType": "ANY",
"definition": {
"id": "gid://shopify/MetafieldDefinition/1071456136",
"name": "Material",
"type": {
"name": "single_line_text_field"
},
"ownerType": "PRODUCT"
}
},
{
"__typename": "CollectionSourceInclusionConditionMetafieldBoolean",
"id": "gid://shopify/CollectionSourceInclusionConditionMetafieldBoolean/937184304",
"value": true,
"definition": {
"id": "gid://shopify/MetafieldDefinition/1071456137",
"name": "Imported",
"type": {
"name": "boolean"
},
"ownerType": "PRODUCTVARIANT"
}
}
]
}
}
]
},
"userErrors": []
}
}