Anchor to metaobjectDefinitionCreatemetaobject
metaobjectDefinitionCreate
mutation
Requires access scope.
Creates a new metaobject definition.
Anchor to Arguments
Arguments
- Anchor to definitiondefinition•Metaobject
Definition requiredCreate Input! The input fields for creating a metaobject definition.
Was this section helpful?
Anchor to MetaobjectDefinitionCreatePayload returnsMetaobjectDefinitionCreatePayload returns
- Anchor to metaobjectDefinitionmetaobject•
Definition The created metaobject definition.
- Anchor to userErrorsuser•
Errors [MetaobjectUser non-nullError!]! The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create a metaobject definition
- Create a metaobject definition with custom access controls
- Create a metaobject definition with the publishable capability enabled
- metaobjectDefinitionCreate reference
Examples
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CreateMetaobjectDefinition($definition: MetaobjectDefinitionCreateInput!) {
metaobjectDefinitionCreate(definition: $definition) {
metaobjectDefinition {
name
type
fieldDefinitions {
name
key
}
}
userErrors {
field
message
code
}
}
}`,
{
variables: {
"definition": {
"name": "Color swatch",
"type": "color-swatch",
"fieldDefinitions": [
{
"name": "Hex",
mutation CreateMetaobjectDefinition($definition: MetaobjectDefinitionCreateInput!) {
metaobjectDefinitionCreate(definition: $definition) {
metaobjectDefinition {
name
type
fieldDefinitions {
name
key
}
}
userErrors {
field
message
code
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CreateMetaobjectDefinition($definition: MetaobjectDefinitionCreateInput!) { metaobjectDefinitionCreate(definition: $definition) { metaobjectDefinition { name type fieldDefinitions { name key } } userErrors { field message code } } }",
"variables": {
"definition": {
"name": "Color swatch",
"type": "color-swatch",
"fieldDefinitions": [
{
"name": "Hex",
"key": "hex",
"type": "single_line_text_field",
"validations": [
{
"name": "regex",
"value": "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"
}
]
}
]
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CreateMetaobjectDefinition($definition: MetaobjectDefinitionCreateInput!) {
metaobjectDefinitionCreate(definition: $definition) {
metaobjectDefinition {
name
type
fieldDefinitions {
name
key
}
}
userErrors {
field
message
code
}
}
}`,
{
variables: {
"definition": {
"name": "Color swatch",
"type": "color-swatch",
"fieldDefinitions": [
{
"name": "Hex",
"key": "hex",
"type": "single_line_text_field",
"validations": [
{
"name": "regex",
"value": "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"
}
]
}
]
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CreateMetaobjectDefinition($definition: MetaobjectDefinitionCreateInput!) {
metaobjectDefinitionCreate(definition: $definition) {
metaobjectDefinition {
name
type
fieldDefinitions {
name
key
}
}
userErrors {
field
message
code
}
}
}`,
"variables": {
"definition": {
"name": "Color swatch",
"type": "color-swatch",
"fieldDefinitions": [
{
"name": "Hex",
"key": "hex",
"type": "single_line_text_field",
"validations": [
{
"name": "regex",
"value": "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"
}
]
}
]
}
},
},
});
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 CreateMetaobjectDefinition($definition: MetaobjectDefinitionCreateInput!) {
metaobjectDefinitionCreate(definition: $definition) {
metaobjectDefinition {
name
type
fieldDefinitions {
name
key
}
}
userErrors {
field
message
code
}
}
}
QUERY
variables = {
"definition": {
"name": "Color swatch",
"type": "color-swatch",
"fieldDefinitions": [{"name"=>"Hex", "key"=>"hex", "type"=>"single_line_text_field", "validations"=>[{"name"=>"regex", "value"=>"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"}]}]
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"definition": {
"name": "Color swatch",
"type": "color-swatch",
"fieldDefinitions": [
{
"name": "Hex",
"key": "hex",
"type": "single_line_text_field",
"validations": [
{
"name": "regex",
"value": "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"
}
]
}
]
}
}
Response
JSON{
"metaobjectDefinitionCreate": {
"metaobjectDefinition": {
"name": "Color swatch",
"type": "color-swatch",
"fieldDefinitions": [
{
"name": "Hex",
"key": "hex"
}
]
},
"userErrors": []
}
}