standardMetafieldDefinitionEnable
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
- •
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 requiredType! 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 BooleanDefault:null Whether metafields for the definition are visible using the Storefront API.
Anchor to StandardMetafieldDefinitionEnablePayload returnsStandardMetafieldDefinitionEnablePayload 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.
- Creates a metafield definition from an existing template
- standardMetafieldDefinitionEnable reference
Examples
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-04/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)