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
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",
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-04/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
JSON{
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "subtitle",
"type": "single_line_text_field",
"value": "Bold Colors"
}
],
"title": "Spring Styles"
}
}
Response
JSON{
"collectionCreate": {
"collection": {
"id": "gid://shopify/Collection/1063001313",
"metafields": {
"edges": [
{
"node": {
"id": "gid://shopify/Metafield/1069228937",
"namespace": "my_field",
"key": "subtitle",
"value": "Bold Colors"
}
}
]
}
},
"userErrors": []
}
}