Anchor to collectionCreatecollection
collectionCreate
mutation
Requires access scope. Also: The app must have access to the input fields used to create the collection. Further, the store must not be on the Starter or Retail plans and user must have a permission to create collection.
Creates a collection.
Anchor to Arguments
Arguments
- Anchor to inputinput•Collection
Input! required The properties to use when creating the collection.
Was this section helpful?
Anchor to CollectionCreatePayload returnsCollectionCreatePayload returns
- Anchor to collectioncollection•
The collection that has been created.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create a new metafield on a new collection
- Create a smart collection with metafield definition conditions
- Creates a custom collection
- Creates a smart collection
- collectionCreate reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation createCollectionMetafields($input: CollectionInput!) {6 collectionCreate(input: $input) {7 collection {8 id9 metafields(first: 3) {10 edges {11 node {12 id13 namespace14 key15 value16 }17 }18 }19 }20 userErrors {21 message22 field23 }24 }25 }`,26 {27 variables: {28 "input": {29 "metafields": [30 {31 "namespace": "my_field",32 "key": "subtitle",33 "type": "single_line_text_field",34 "value": "Bold Colors"35 }36 ],37 "title": "Spring Styles"38 }39 },40 },41);4243const data = await response.json();44
mutation createCollectionMetafields($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation createCollectionMetafields($input: CollectionInput!) { collectionCreate(input: $input) { collection { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }",
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
],
"title": "Spring Styles"
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation createCollectionMetafields($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
{
variables: {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
],
"title": "Spring Styles"
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation createCollectionMetafields($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
],
"title": "Spring Styles"
}
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation createCollectionMetafields($input: CollectionInput!) {
collectionCreate(input: $input) {
collection {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
QUERY
variables = {
"input": {
"metafields": [{"namespace"=>"my_field", "key"=>"subtitle", "type"=>"single_line_text_field", "value"=>"Bold Colors"}],
"title": "Spring Styles"
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "input": {3 "metafields": [4 {5 "namespace": "my_field",6 "key": "subtitle",7 "type": "single_line_text_field",8 "value": "Bold Colors"9 }10 ],11 "title": "Spring Styles"12 }13}
Response
JSON1{2 "collectionCreate": {3 "collection": {4 "id": "gid://shopify/Collection/1063001313",5 "metafields": {6 "edges": [7 {8 "node": {9 "id": "gid://shopify/Metafield/1069228937",10 "namespace": "my_field",11 "key": "subtitle",12 "value": "Bold Colors"13 }14 }15 ]16 }17 },18 "userErrors": []19 }20}