Creates a metafield definition from an existing template
Description
Enable a Shopify [standard metafield definition template](https://shopify.dev/docs/apps/build/metafields/list-of-standard-definitions) instead of creating a custom definition. The created definition takes its name, namespace, key, and description from the template. This example enables the care guide template for products and uses `access.storefront` to make the metafields under the definition readable through the Storefront API.
Query
mutation standardMetafieldDefinitionEnable($id: ID!, $ownerType: MetafieldOwnerType!, $pin: Boolean!, $access: StandardMetafieldDefinitionAccessInput) {
standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, access: $access) {
createdDefinition {
name
key
namespace
description
access {
storefront
}
}
userErrors {
field
message
code
}
}
}
Variables
{
"id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",
"ownerType": "PRODUCT",
"pin": false,
"access": {
"storefront": "PUBLIC_READ"
}
}
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 standardMetafieldDefinitionEnable($id: ID!, $ownerType: MetafieldOwnerType!, $pin: Boolean!, $access: StandardMetafieldDefinitionAccessInput) { standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, access: $access) { createdDefinition { name key namespace description access { storefront } } userErrors { field message code } } }",
"variables": {
"id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",
"ownerType": "PRODUCT",
"pin": false,
"access": {
"storefront": "PUBLIC_READ"
}
}
}'
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 standardMetafieldDefinitionEnable($id: ID!, $ownerType: MetafieldOwnerType!, $pin: Boolean!, $access: StandardMetafieldDefinitionAccessInput) {
standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, access: $access) {
createdDefinition {
name
key
namespace
description
access {
storefront
}
}
userErrors {
field
message
code
}
}
}`,
{
variables: {
"id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",
"ownerType": "PRODUCT",
"pin": false,
"access": {
"storefront": "PUBLIC_READ"
}
},
},
);
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 standardMetafieldDefinitionEnable($id: ID!, $ownerType: MetafieldOwnerType!, $pin: Boolean!, $access: StandardMetafieldDefinitionAccessInput) {
standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, access: $access) {
createdDefinition {
name
key
namespace
description
access {
storefront
}
}
userErrors {
field
message
code
}
}
}
QUERY
variables = {
"id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",
"ownerType": "PRODUCT",
"pin": false,
"access": {
"storefront": "PUBLIC_READ"
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation standardMetafieldDefinitionEnable($id: ID!, $ownerType: MetafieldOwnerType!, $pin: Boolean!, $access: StandardMetafieldDefinitionAccessInput) {
standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, access: $access) {
createdDefinition {
name
key
namespace
description
access {
storefront
}
}
userErrors {
field
message
code
}
}
}`,
"variables": {
"id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",
"ownerType": "PRODUCT",
"pin": false,
"access": {
"storefront": "PUBLIC_READ"
}
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation standardMetafieldDefinitionEnable($id: ID!, $ownerType: MetafieldOwnerType!, $pin: Boolean!, $access: StandardMetafieldDefinitionAccessInput) {
standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, access: $access) {
createdDefinition {
name
key
namespace
description
access {
storefront
}
}
userErrors {
field
message
code
}
}
}' \
--variables \
'{
"id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",
"ownerType": "PRODUCT",
"pin": false,
"access": {
"storefront": "PUBLIC_READ"
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2027-01/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation standardMetafieldDefinitionEnable($id: ID!, $ownerType: MetafieldOwnerType!, $pin: Boolean!, $access: StandardMetafieldDefinitionAccessInput) {
standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, access: $access) {
createdDefinition {
name
key
namespace
description
access {
storefront
}
}
userErrors {
field
message
code
}
}
}
`,
variables: {
"id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",
"ownerType": "PRODUCT",
"pin": false,
"access": {
"storefront": "PUBLIC_READ"
}
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"standardMetafieldDefinitionEnable": {
"createdDefinition": {
"name": "Care guide",
"key": "care_guide",
"namespace": "descriptors",
"description": "Instructions for taking care of a product or apparel",
"access": {
"storefront": "PUBLIC_READ"
}
},
"userErrors": []
}
}