Add an existing source to a collection
Description
Add an existing shareable source to a collection. Use `shareableSource` with a `sourceId` when an app
has already created a reusable source and wants to link it to another collection.
Query
mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToCreate": [
{
"shareableSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2027-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionUpdate($collection: CollectionUpdateInput!) { collectionUpdate(collection: $collection) { collection { id title sources { __typename id title } } userErrors { field message } } }",
"variables": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToCreate": [
{
"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 CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToCreate": [
{
"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 CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToCreate": [
{
"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 CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToCreate": [
{
"shareableSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToCreate": [
{
"shareableSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2027-01/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToCreate": [
{
"shareableSource": {
"sourceId": "gid://shopify/CollectionConditionsSource/129168209"
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionUpdate": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "All snowboards",
"sources": [
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/823919097",
"title": "All Snowboards Source"
},
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/129168209",
"title": "Shareable Source Owned By Shopify Web"
}
]
},
"userErrors": []
}
}
Apply a rule on a custom collection
Description
Add automated membership to a hand-picked collection by creating a conditions source with
`sourcesToCreate`. This example adds a source with a `variantCompareAtPrice` condition that uses the
`IS_SET` relation, so the new source provides products that have a variant with a compare-at price.
The collection keeps its existing source, and the new source is added after it.
Query
mutation AddConditionsSourceToCollection($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionVariantCompareAtPrice {
relation
value {
amount
currencyCode
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"id": "gid://shopify/Collection/442946009",
"sourcesToCreate": [
{
"source": {
"title": "Products on sale",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"variantCompareAtPrice": {
"relation": "IS_SET"
}
}
]
}
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2027-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation AddConditionsSourceToCollection($collection: CollectionUpdateInput!) { collectionUpdate(collection: $collection) { collection { id title handle sources { __typename id title ... on CollectionConditionsSource { inclusion { matchType conditions { __typename id ... on CollectionSourceInclusionConditionVariantCompareAtPrice { relation value { amount currencyCode } } } } } } } userErrors { field message } } }",
"variables": {
"collection": {
"id": "gid://shopify/Collection/442946009",
"sourcesToCreate": [
{
"source": {
"title": "Products on sale",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"variantCompareAtPrice": {
"relation": "IS_SET"
}
}
]
}
}
}
]
}
}
}'
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 AddConditionsSourceToCollection($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionVariantCompareAtPrice {
relation
value {
amount
currencyCode
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"id": "gid://shopify/Collection/442946009",
"sourcesToCreate": [
{
"source": {
"title": "Products on sale",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"variantCompareAtPrice": {
"relation": "IS_SET"
}
}
]
}
}
}
]
}
},
},
);
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 AddConditionsSourceToCollection($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionVariantCompareAtPrice {
relation
value {
amount
currencyCode
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"id": "gid://shopify/Collection/442946009",
"sourcesToCreate": [
{
"source": {
"title": "Products on sale",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"variantCompareAtPrice": {
"relation": "IS_SET"
}
}
]
}
}
}
]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation AddConditionsSourceToCollection($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionVariantCompareAtPrice {
relation
value {
amount
currencyCode
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"id": "gid://shopify/Collection/442946009",
"sourcesToCreate": [
{
"source": {
"title": "Products on sale",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"variantCompareAtPrice": {
"relation": "IS_SET"
}
}
]
}
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation AddConditionsSourceToCollection($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionVariantCompareAtPrice {
relation
value {
amount
currencyCode
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"id": "gid://shopify/Collection/442946009",
"sourcesToCreate": [
{
"source": {
"title": "Products on sale",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"variantCompareAtPrice": {
"relation": "IS_SET"
}
}
]
}
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2027-01/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation AddConditionsSourceToCollection($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionVariantCompareAtPrice {
relation
value {
amount
currencyCode
}
}
}
}
}
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"id": "gid://shopify/Collection/442946009",
"sourcesToCreate": [
{
"source": {
"title": "Products on sale",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"variantCompareAtPrice": {
"relation": "IS_SET"
}
}
]
}
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionUpdate": {
"collection": {
"id": "gid://shopify/Collection/442946009",
"title": "All products - handpicked!",
"handle": "everything-custom",
"sources": [
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/355527071",
"title": "All Products Handpicked Source",
"inclusion": {
"matchType": null,
"conditions": []
}
},
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/1061390157",
"title": "Products on sale",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"__typename": "CollectionSourceInclusionConditionVariantCompareAtPrice",
"id": "gid://shopify/CollectionSourceInclusionConditionVariantCompareAtPrice/1061390158",
"relation": "IS_SET",
"value": null
}
]
}
}
]
},
"userErrors": []
}
}
Create a new metafield and update another on an existing collection
Description
Create a new metafield `my_field.subtitle` and update an
existing metafield `my_fields.target_audience` on a specific
collection.
Alternatively, refer to the
[metafieldsSet](https://shopify.dev/api/admin-graphql/latest/mutations/metafieldsset) mutation
to create and/or update metafields on collection resources.
Query
mutation updateCollectionMetafields($input: CollectionInput!) {
collectionUpdate(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"
},
{
"id": "gid://shopify/Metafield/1069229037",
"value": "New Mothers"
}
],
"id": "gid://shopify/Collection/79210309"
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2027-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation updateCollectionMetafields($input: CollectionInput!) { collectionUpdate(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"
},
{
"id": "gid://shopify/Metafield/1069229037",
"value": "New Mothers"
}
],
"id": "gid://shopify/Collection/79210309"
}
}
}'
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 updateCollectionMetafields($input: CollectionInput!) {
collectionUpdate(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"
},
{
"id": "gid://shopify/Metafield/1069229037",
"value": "New Mothers"
}
],
"id": "gid://shopify/Collection/79210309"
}
},
},
);
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 updateCollectionMetafields($input: CollectionInput!) {
collectionUpdate(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"
},
{
"id": "gid://shopify/Metafield/1069229037",
"value": "New Mothers"
}
],
"id": "gid://shopify/Collection/79210309"
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation updateCollectionMetafields($input: CollectionInput!) {
collectionUpdate(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"
},
{
"id": "gid://shopify/Metafield/1069229037",
"value": "New Mothers"
}
],
"id": "gid://shopify/Collection/79210309"
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation updateCollectionMetafields($input: CollectionInput!) {
collectionUpdate(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"
},
{
"id": "gid://shopify/Metafield/1069229037",
"value": "New Mothers"
}
],
"id": "gid://shopify/Collection/79210309"
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2027-01/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation updateCollectionMetafields($input: CollectionInput!) {
collectionUpdate(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"
},
{
"id": "gid://shopify/Metafield/1069229037",
"value": "New Mothers"
}
],
"id": "gid://shopify/Collection/79210309"
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionUpdate": {
"collection": {
"id": "gid://shopify/Collection/79210309",
"metafields": {
"edges": [
{
"node": {
"id": "gid://shopify/Metafield/1069229037",
"namespace": "my_fields",
"key": "target_audience",
"value": "New Mothers"
}
},
{
"node": {
"id": "gid://shopify/Metafield/1069229038",
"namespace": "my_field",
"key": "subtitle",
"value": "Bold Colors"
}
}
]
}
},
"userErrors": []
}
}
Delete the collection's image
Description
Remove a collection's image by passing `null` for `image`. The collection's other fields don't
change. To keep the current image when you update other fields, leave `image` out of the input.
Query
mutation DeleteCollectionImage($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
image {
url
altText
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"id": "gid://shopify/Collection/1007901140",
"image": null
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2027-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation DeleteCollectionImage($collection: CollectionUpdateInput!) { collectionUpdate(collection: $collection) { collection { id title image { url altText } } userErrors { field message } } }",
"variables": {
"collection": {
"id": "gid://shopify/Collection/1007901140",
"image": null
}
}
}'
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 DeleteCollectionImage($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
image {
url
altText
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"id": "gid://shopify/Collection/1007901140",
"image": null
}
},
},
);
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 DeleteCollectionImage($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
image {
url
altText
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"id": "gid://shopify/Collection/1007901140",
"image": null
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation DeleteCollectionImage($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
image {
url
altText
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"id": "gid://shopify/Collection/1007901140",
"image": null
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation DeleteCollectionImage($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
image {
url
altText
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"id": "gid://shopify/Collection/1007901140",
"image": null
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2027-01/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation DeleteCollectionImage($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
image {
url
altText
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"id": "gid://shopify/Collection/1007901140",
"image": null
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionUpdate": {
"collection": {
"id": "gid://shopify/Collection/1007901140",
"title": "Featured items",
"image": null
},
"userErrors": []
}
}
Remove a source from a collection
Description
Remove a source from a collection by passing the source ID to `sourcesToDelete`.
Query
mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"id": "gid://shopify/Collection/247865063",
"sourcesToDelete": [
"gid://shopify/CollectionConditionsSource/562928290"
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2027-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionUpdate($collection: CollectionUpdateInput!) { collectionUpdate(collection: $collection) { collection { id title sources { __typename id title } } userErrors { field message } } }",
"variables": {
"collection": {
"id": "gid://shopify/Collection/247865063",
"sourcesToDelete": [
"gid://shopify/CollectionConditionsSource/562928290"
]
}
}
}'
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 CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"id": "gid://shopify/Collection/247865063",
"sourcesToDelete": [
"gid://shopify/CollectionConditionsSource/562928290"
]
}
},
},
);
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 CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"id": "gid://shopify/Collection/247865063",
"sourcesToDelete": [
"gid://shopify/CollectionConditionsSource/562928290"
]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"id": "gid://shopify/Collection/247865063",
"sourcesToDelete": [
"gid://shopify/CollectionConditionsSource/562928290"
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"id": "gid://shopify/Collection/247865063",
"sourcesToDelete": [
"gid://shopify/CollectionConditionsSource/562928290"
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2027-01/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
sources {
__typename
id
title
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"id": "gid://shopify/Collection/247865063",
"sourcesToDelete": [
"gid://shopify/CollectionConditionsSource/562928290"
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionUpdate": {
"collection": {
"id": "gid://shopify/Collection/247865063",
"title": "Collection Snowboards",
"sources": []
},
"userErrors": []
}
}
Update a collection and add a source
Description
Update collection details and add a source that determines which products are included. This example
demonstrates how to update collection metadata, SEO fields, metafields, an image, and source-based
membership in a single mutation.
Query
mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(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 {
relation
values
matchType
}
}
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
job {
id
done
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Updated spring styles",
"descriptionHtml": "Updated products for the <strong>spring</strong> season.",
"handle": "updated-spring-styles",
"redirectNewHandle": true,
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/f478bbc6-31d8-43fd-bada-cc802a8192e7/test_file.txt",
"altText": "Updated spring collection image"
},
"seo": {
"title": "Updated spring styles collection",
"description": "Browse updated spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "updated_season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sourcesToCreate": [
{
"source": {
"title": "Updated source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
}
],
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2027-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionUpdate($collection: CollectionUpdateInput!) { collectionUpdate(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 { relation values matchType } } selections(first: 10) { nodes { product { id title } variantIds } } } } } } job { id done } userErrors { field message } } }",
"variables": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Updated spring styles",
"descriptionHtml": "Updated products for the <strong>spring</strong> season.",
"handle": "updated-spring-styles",
"redirectNewHandle": true,
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/f478bbc6-31d8-43fd-bada-cc802a8192e7/test_file.txt",
"altText": "Updated spring collection image"
},
"seo": {
"title": "Updated spring styles collection",
"description": "Browse updated spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "updated_season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sourcesToCreate": [
{
"source": {
"title": "Updated source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"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 CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(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 {
relation
values
matchType
}
}
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
job {
id
done
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Updated spring styles",
"descriptionHtml": "Updated products for the <strong>spring</strong> season.",
"handle": "updated-spring-styles",
"redirectNewHandle": true,
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/f478bbc6-31d8-43fd-bada-cc802a8192e7/test_file.txt",
"altText": "Updated spring collection image"
},
"seo": {
"title": "Updated spring styles collection",
"description": "Browse updated spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "updated_season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sourcesToCreate": [
{
"source": {
"title": "Updated source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"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 CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(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 {
relation
values
matchType
}
}
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
job {
id
done
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Updated spring styles",
"descriptionHtml": "Updated products for the <strong>spring</strong> season.",
"handle": "updated-spring-styles",
"redirectNewHandle": true,
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/f478bbc6-31d8-43fd-bada-cc802a8192e7/test_file.txt",
"altText": "Updated spring collection image"
},
"seo": {
"title": "Updated spring styles collection",
"description": "Browse updated spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "updated_season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sourcesToCreate": [
{
"source": {
"title": "Updated source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"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 CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(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 {
relation
values
matchType
}
}
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
job {
id
done
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Updated spring styles",
"descriptionHtml": "Updated products for the <strong>spring</strong> season.",
"handle": "updated-spring-styles",
"redirectNewHandle": true,
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/f478bbc6-31d8-43fd-bada-cc802a8192e7/test_file.txt",
"altText": "Updated spring collection image"
},
"seo": {
"title": "Updated spring styles collection",
"description": "Browse updated spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "updated_season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sourcesToCreate": [
{
"source": {
"title": "Updated source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
}
],
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(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 {
relation
values
matchType
}
}
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
job {
id
done
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Updated spring styles",
"descriptionHtml": "Updated products for the <strong>spring</strong> season.",
"handle": "updated-spring-styles",
"redirectNewHandle": true,
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/f478bbc6-31d8-43fd-bada-cc802a8192e7/test_file.txt",
"altText": "Updated spring collection image"
},
"seo": {
"title": "Updated spring styles collection",
"description": "Browse updated spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "updated_season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sourcesToCreate": [
{
"source": {
"title": "Updated source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
}
],
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2027-01/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(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 {
relation
values
matchType
}
}
selections(first: 10) {
nodes {
product {
id
title
}
variantIds
}
}
}
}
}
}
job {
id
done
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Updated spring styles",
"descriptionHtml": "Updated products for the <strong>spring</strong> season.",
"handle": "updated-spring-styles",
"redirectNewHandle": true,
"templateSuffix": "spring",
"sortOrder": "MANUAL",
"image": {
"src": "tmp/26371970/collections/f478bbc6-31d8-43fd-bada-cc802a8192e7/test_file.txt",
"altText": "Updated spring collection image"
},
"seo": {
"title": "Updated spring styles collection",
"description": "Browse updated spring products."
},
"metafields": [
{
"namespace": "custom",
"key": "updated_season",
"type": "single_line_text_field",
"value": "spring"
}
],
"sourcesToCreate": [
{
"source": {
"title": "Updated source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
}
],
"selections": [
{
"productId": "gid://shopify/Product/20995642"
}
]
}
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionUpdate": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Updated spring styles",
"descriptionHtml": "Updated products for the <strong>spring</strong> season.",
"handle": "updated-spring-styles",
"sortOrder": "MANUAL",
"templateSuffix": "spring",
"image": {
"url": "https://cdn.shopify.com/s/files/1/2637/1970/collections/test_file.jpg?v=1781273020",
"altText": "Updated spring collection image"
},
"seo": {
"title": "Updated spring styles collection",
"description": "Browse updated spring products."
},
"metafields": {
"nodes": [
{
"namespace": "notes",
"key": "descriptionription",
"value": "Collection descriptionription"
},
{
"namespace": "definition",
"key": "some_list",
"value": "[\"valid value 0\",\"valid value 1\",\"valid value 2\"]"
},
{
"namespace": "definition",
"key": "some_integer",
"value": "5"
},
{
"namespace": "global",
"key": "title_tag",
"value": "Updated spring styles collection"
},
{
"namespace": "global",
"key": "description_tag",
"value": "Browse updated spring products."
},
{
"namespace": "custom",
"key": "updated_season",
"value": "spring"
}
]
},
"sources": [
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/1047893300",
"title": "Updated source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"__typename": "CollectionSourceInclusionConditionProductTag",
"id": "gid://shopify/CollectionSourceInclusionConditionProductTag/977278334",
"relation": "TAGGED_WITH",
"values": [
"spring"
],
"matchType": "ANY"
}
],
"selections": {
"nodes": [
{
"product": {
"id": "gid://shopify/Product/20995642",
"title": "Element"
},
"variantIds": null
}
]
}
}
}
]
},
"job": null,
"userErrors": []
}
}
Update the collection's handle
Description
Change a collection's `handle`, which sets the collection's URL path in the online store. Set
`redirectNewHandle` to `true` to also create a URL redirect from the old path to the new one, so
that existing links to the collection keep working.
Query
mutation UpdateCollectionHandle($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"id": "gid://shopify/Collection/142458073",
"handle": "winter-snowboards",
"redirectNewHandle": true
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2027-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation UpdateCollectionHandle($collection: CollectionUpdateInput!) { collectionUpdate(collection: $collection) { collection { id title handle } userErrors { field message } } }",
"variables": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"handle": "winter-snowboards",
"redirectNewHandle": 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 UpdateCollectionHandle($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"id": "gid://shopify/Collection/142458073",
"handle": "winter-snowboards",
"redirectNewHandle": 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 UpdateCollectionHandle($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"id": "gid://shopify/Collection/142458073",
"handle": "winter-snowboards",
"redirectNewHandle": 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 UpdateCollectionHandle($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"handle": "winter-snowboards",
"redirectNewHandle": true
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation UpdateCollectionHandle($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"id": "gid://shopify/Collection/142458073",
"handle": "winter-snowboards",
"redirectNewHandle": true
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2027-01/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation UpdateCollectionHandle($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"id": "gid://shopify/Collection/142458073",
"handle": "winter-snowboards",
"redirectNewHandle": true
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionUpdate": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "All snowboards",
"handle": "winter-snowboards"
},
"userErrors": []
}
}
Update the collection's rule set
Description
Replace the inclusion conditions of a collection's existing source by passing the source's ID to
`sourcesToUpdate`. This example deletes the source's current condition with `conditionsToDelete`,
creates a `variantPrice` condition and a `productTag` condition with `conditionsToCreate`, and sets
`matchType` to `ANY`, so the collection includes products that meet one or more of the conditions.
Use `sourcesToUpdate` when you want to change which products an existing source includes without
removing the source from the collection.
Query
mutation UpdateCollectionSourceConditions($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionVariantPrice {
variantPriceRelation: relation
value {
amount
currencyCode
}
}
... on CollectionSourceInclusionConditionProductTag {
productTagRelation: relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToUpdate": [
{
"condition": {
"id": "gid://shopify/CollectionConditionsSource/823919097",
"inclusion": {
"matchType": "ANY",
"conditionsToDelete": [
"gid://shopify/CollectionSourceInclusionConditionProductType/282187218"
],
"conditionsToCreate": [
{
"variantPrice": {
"relation": "LESS_THAN",
"value": {
"amount": "200.0",
"currencyCode": "USD"
}
}
},
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"board"
],
"matchType": "ANY"
}
}
]
}
}
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2027-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation UpdateCollectionSourceConditions($collection: CollectionUpdateInput!) { collectionUpdate(collection: $collection) { collection { id title handle sources { __typename id title ... on CollectionConditionsSource { inclusion { matchType conditions { __typename id ... on CollectionSourceInclusionConditionVariantPrice { variantPriceRelation: relation value { amount currencyCode } } ... on CollectionSourceInclusionConditionProductTag { productTagRelation: relation values matchType } } } } } } userErrors { field message } } }",
"variables": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToUpdate": [
{
"condition": {
"id": "gid://shopify/CollectionConditionsSource/823919097",
"inclusion": {
"matchType": "ANY",
"conditionsToDelete": [
"gid://shopify/CollectionSourceInclusionConditionProductType/282187218"
],
"conditionsToCreate": [
{
"variantPrice": {
"relation": "LESS_THAN",
"value": {
"amount": "200.0",
"currencyCode": "USD"
}
}
},
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"board"
],
"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 UpdateCollectionSourceConditions($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionVariantPrice {
variantPriceRelation: relation
value {
amount
currencyCode
}
}
... on CollectionSourceInclusionConditionProductTag {
productTagRelation: relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToUpdate": [
{
"condition": {
"id": "gid://shopify/CollectionConditionsSource/823919097",
"inclusion": {
"matchType": "ANY",
"conditionsToDelete": [
"gid://shopify/CollectionSourceInclusionConditionProductType/282187218"
],
"conditionsToCreate": [
{
"variantPrice": {
"relation": "LESS_THAN",
"value": {
"amount": "200.0",
"currencyCode": "USD"
}
}
},
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"board"
],
"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 UpdateCollectionSourceConditions($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionVariantPrice {
variantPriceRelation: relation
value {
amount
currencyCode
}
}
... on CollectionSourceInclusionConditionProductTag {
productTagRelation: relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToUpdate": [
{
"condition": {
"id": "gid://shopify/CollectionConditionsSource/823919097",
"inclusion": {
"matchType": "ANY",
"conditionsToDelete": [
"gid://shopify/CollectionSourceInclusionConditionProductType/282187218"
],
"conditionsToCreate": [
{
"variantPrice": {
"relation": "LESS_THAN",
"value": {
"amount": "200.0",
"currencyCode": "USD"
}
}
},
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"board"
],
"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 UpdateCollectionSourceConditions($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionVariantPrice {
variantPriceRelation: relation
value {
amount
currencyCode
}
}
... on CollectionSourceInclusionConditionProductTag {
productTagRelation: relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToUpdate": [
{
"condition": {
"id": "gid://shopify/CollectionConditionsSource/823919097",
"inclusion": {
"matchType": "ANY",
"conditionsToDelete": [
"gid://shopify/CollectionSourceInclusionConditionProductType/282187218"
],
"conditionsToCreate": [
{
"variantPrice": {
"relation": "LESS_THAN",
"value": {
"amount": "200.0",
"currencyCode": "USD"
}
}
},
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"board"
],
"matchType": "ANY"
}
}
]
}
}
}
]
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation UpdateCollectionSourceConditions($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionVariantPrice {
variantPriceRelation: relation
value {
amount
currencyCode
}
}
... on CollectionSourceInclusionConditionProductTag {
productTagRelation: relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToUpdate": [
{
"condition": {
"id": "gid://shopify/CollectionConditionsSource/823919097",
"inclusion": {
"matchType": "ANY",
"conditionsToDelete": [
"gid://shopify/CollectionSourceInclusionConditionProductType/282187218"
],
"conditionsToCreate": [
{
"variantPrice": {
"relation": "LESS_THAN",
"value": {
"amount": "200.0",
"currencyCode": "USD"
}
}
},
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"board"
],
"matchType": "ANY"
}
}
]
}
}
}
]
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2027-01/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation UpdateCollectionSourceConditions($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionVariantPrice {
variantPriceRelation: relation
value {
amount
currencyCode
}
}
... on CollectionSourceInclusionConditionProductTag {
productTagRelation: relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"id": "gid://shopify/Collection/142458073",
"sourcesToUpdate": [
{
"condition": {
"id": "gid://shopify/CollectionConditionsSource/823919097",
"inclusion": {
"matchType": "ANY",
"conditionsToDelete": [
"gid://shopify/CollectionSourceInclusionConditionProductType/282187218"
],
"conditionsToCreate": [
{
"variantPrice": {
"relation": "LESS_THAN",
"value": {
"amount": "200.0",
"currencyCode": "USD"
}
}
},
{
"productTag": {
"relation": "TAGGED_WITH",
"values": [
"board"
],
"matchType": "ANY"
}
}
]
}
}
}
]
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionUpdate": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "All snowboards",
"handle": "snowboards",
"sources": [
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/823919097",
"title": "All Snowboards Source",
"inclusion": {
"matchType": "ANY",
"conditions": [
{
"__typename": "CollectionSourceInclusionConditionVariantPrice",
"id": "gid://shopify/CollectionSourceInclusionConditionVariantPrice/1061390155",
"variantPriceRelation": "LESS_THAN",
"value": {
"amount": "200.0",
"currencyCode": "USD"
}
},
{
"__typename": "CollectionSourceInclusionConditionProductTag",
"id": "gid://shopify/CollectionSourceInclusionConditionProductTag/1061390156",
"productTagRelation": "TAGGED_WITH",
"values": [
"board"
],
"matchType": "ANY"
}
]
}
}
]
},
"userErrors": []
}
}
Updates an existing custom collection
Description
Rename a custom collection and replace its description by passing `title` and `descriptionHtml`.
Fields that you leave out of the input keep their current values, so the collection's `handle`
doesn't change.
Query
mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
description
descriptionHtml
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"id": "gid://shopify/Collection/711838235",
"title": "Summer sale",
"descriptionHtml": "<p>Snowboards and gear at <strong>end-of-season</strong> prices.</p>"
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2027-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CollectionUpdate($collection: CollectionUpdateInput!) { collectionUpdate(collection: $collection) { collection { id title handle description descriptionHtml } userErrors { field message } } }",
"variables": {
"collection": {
"id": "gid://shopify/Collection/711838235",
"title": "Summer sale",
"descriptionHtml": "<p>Snowboards and gear at <strong>end-of-season</strong> prices.</p>"
}
}
}'
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 CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
description
descriptionHtml
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"id": "gid://shopify/Collection/711838235",
"title": "Summer sale",
"descriptionHtml": "<p>Snowboards and gear at <strong>end-of-season</strong> prices.</p>"
}
},
},
);
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 CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
description
descriptionHtml
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"id": "gid://shopify/Collection/711838235",
"title": "Summer sale",
"descriptionHtml": "<p>Snowboards and gear at <strong>end-of-season</strong> prices.</p>"
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
description
descriptionHtml
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"id": "gid://shopify/Collection/711838235",
"title": "Summer sale",
"descriptionHtml": "<p>Snowboards and gear at <strong>end-of-season</strong> prices.</p>"
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
description
descriptionHtml
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"id": "gid://shopify/Collection/711838235",
"title": "Summer sale",
"descriptionHtml": "<p>Snowboards and gear at <strong>end-of-season</strong> prices.</p>"
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2027-01/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation CollectionUpdate($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
description
descriptionHtml
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"id": "gid://shopify/Collection/711838235",
"title": "Summer sale",
"descriptionHtml": "<p>Snowboards and gear at <strong>end-of-season</strong> prices.</p>"
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionUpdate": {
"collection": {
"id": "gid://shopify/Collection/711838235",
"title": "Summer sale",
"handle": "onsale",
"description": "Snowboards and gear at end-of-season prices.",
"descriptionHtml": "<p>Snowboards and gear at <strong>end-of-season</strong> prices.</p>"
},
"userErrors": []
}
}
Updates an existing smart collection
Description
Rename a rule-based collection and change how its products are sorted by passing `title` and
`sortOrder`. The input doesn't include `sourcesToCreate`, `sourcesToUpdate` or `sourcesToDelete`, so
the collection's source and its conditions stay as they are.
Query
mutation UpdateSmartCollection($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductType {
relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}
Variables
{
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Snowboards by price",
"sortOrder": "PRICE_ASC"
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2027-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation UpdateSmartCollection($collection: CollectionUpdateInput!) { collectionUpdate(collection: $collection) { collection { id title handle sortOrder sources { __typename id title ... on CollectionConditionsSource { inclusion { matchType conditions { __typename id ... on CollectionSourceInclusionConditionProductType { relation values matchType } } } } } } userErrors { field message } } }",
"variables": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Snowboards by price",
"sortOrder": "PRICE_ASC"
}
}
}'
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 UpdateSmartCollection($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductType {
relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Snowboards by price",
"sortOrder": "PRICE_ASC"
}
},
},
);
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 UpdateSmartCollection($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductType {
relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Snowboards by price",
"sortOrder": "PRICE_ASC"
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation UpdateSmartCollection($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductType {
relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Snowboards by price",
"sortOrder": "PRICE_ASC"
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation UpdateSmartCollection($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductType {
relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Snowboards by price",
"sortOrder": "PRICE_ASC"
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2027-01/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation UpdateSmartCollection($collection: CollectionUpdateInput!) {
collectionUpdate(collection: $collection) {
collection {
id
title
handle
sortOrder
sources {
__typename
id
title
... on CollectionConditionsSource {
inclusion {
matchType
conditions {
__typename
id
... on CollectionSourceInclusionConditionProductType {
relation
values
matchType
}
}
}
}
}
}
userErrors {
field
message
}
}
}
`,
variables: {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Snowboards by price",
"sortOrder": "PRICE_ASC"
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"collectionUpdate": {
"collection": {
"id": "gid://shopify/Collection/142458073",
"title": "Snowboards by price",
"handle": "snowboards",
"sortOrder": "PRICE_ASC",
"sources": [
{
"__typename": "CollectionConditionsSource",
"id": "gid://shopify/CollectionConditionsSource/823919097",
"title": "All Snowboards Source",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"__typename": "CollectionSourceInclusionConditionProductType",
"id": "gid://shopify/CollectionSourceInclusionConditionProductType/282187218",
"relation": "EQUALS",
"values": [
"Snowboards"
],
"matchType": "ALL"
}
]
}
}
]
},
"userErrors": []
}
}