standard Metafield Definition Enable
Requires API client to have access to the resource type associated with the metafield definition owner type.
Activates the specified standard metafield definition from its template.
Refer to the list of standard metafield definition templates.
Arguments
- Anchor to accessaccess•
The access settings that apply to each of the metafields that belong to the metafield definition.
- •
The ID of the standard metafield definition template to enable.
- •
The key of the standard metafield to enable. Used in combination with
namespace
.- Anchor to namespacenamespace•
The namespace of the standard metafield to enable. Used in combination with
key
.- Anchor to ownerTypeowner•
Type MetafieldOwner Type!required The resource type that the metafield definition is scoped to.
- •
Whether to pin the metafield definition.
- Anchor to useAsCollectionConditionuse•
As Collection Condition BooleanDefault:false Whether the metafield definition can be used as a collection condition.
- Anchor to visibleToStorefrontApivisible•
To Storefront Api Whether metafields for the definition are visible using the Storefront API. Use
access.storefront
instead.
Anchor to StandardMetafieldDefinitionEnablePayload returnsStandard Metafield Definition Enable Payload returns
- Anchor to createdDefinitioncreated•
Definition The metafield definition that was created.
- Anchor to userErrorsuser•
Errors The list of errors that occurred from executing the mutation.
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation standardMetafieldDefinitionEnable($id: ID!, $ownerType: MetafieldOwnerType!, $pin: Boolean!, $visibleToStorefrontApi: Boolean!) {6 standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, visibleToStorefrontApi: $visibleToStorefrontApi) {7 createdDefinition {8 name9 key10 namespace11 description12 }13 userErrors {14 field15 message16 }17 }18 }`,19 {20 variables: {21 "id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",22 "ownerType": "PRODUCT",23 "pin": false,24 "visibleToStorefrontApi": true25 },26 },27);2829const data = await response.json();30
mutation standardMetafieldDefinitionEnable($id: ID!, $ownerType: MetafieldOwnerType!, $pin: Boolean!, $visibleToStorefrontApi: Boolean!) {
standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, visibleToStorefrontApi: $visibleToStorefrontApi) {
createdDefinition {
name
key
namespace
description
}
userErrors {
field
message
}
}
}
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 standardMetafieldDefinitionEnable($id: ID!, $ownerType: MetafieldOwnerType!, $pin: Boolean!, $visibleToStorefrontApi: Boolean!) { standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, visibleToStorefrontApi: $visibleToStorefrontApi) { createdDefinition { name key namespace description } userErrors { field message } } }",
"variables": {
"id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",
"ownerType": "PRODUCT",
"pin": false,
"visibleToStorefrontApi": true
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation standardMetafieldDefinitionEnable($id: ID!, $ownerType: MetafieldOwnerType!, $pin: Boolean!, $visibleToStorefrontApi: Boolean!) {
standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, visibleToStorefrontApi: $visibleToStorefrontApi) {
createdDefinition {
name
key
namespace
description
}
userErrors {
field
message
}
}
}`,
{
variables: {
"id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",
"ownerType": "PRODUCT",
"pin": false,
"visibleToStorefrontApi": true
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation standardMetafieldDefinitionEnable($id: ID!, $ownerType: MetafieldOwnerType!, $pin: Boolean!, $visibleToStorefrontApi: Boolean!) {
standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, visibleToStorefrontApi: $visibleToStorefrontApi) {
createdDefinition {
name
key
namespace
description
}
userErrors {
field
message
}
}
}`,
"variables": {
"id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",
"ownerType": "PRODUCT",
"pin": false,
"visibleToStorefrontApi": true
},
},
});
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!, $visibleToStorefrontApi: Boolean!) {
standardMetafieldDefinitionEnable(id: $id, ownerType: $ownerType, pin: $pin, visibleToStorefrontApi: $visibleToStorefrontApi) {
createdDefinition {
name
key
namespace
description
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",
"ownerType": "PRODUCT",
"pin": false,
"visibleToStorefrontApi": true
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",3 "ownerType": "PRODUCT",4 "pin": false,5 "visibleToStorefrontApi": true6}
Response
JSON1{2 "standardMetafieldDefinitionEnable": {3 "createdDefinition": {4 "name": "Care guide",5 "key": "care_guide",6 "namespace": "descriptors",7 "description": "Instructions for taking care of a product or apparel"8 },9 "userErrors": []10 }11}