Anchor to section titled 'undefined'

standardMetafieldDefinitionEnable
mutation

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.


The ID of the standard metafield definition template to enable.

The key of the standard metafield to enable. Used in combination with namespace.

The namespace of the standard metafield to enable. Used in combination with key.

The resource type that the metafield definition is scoped to.

Anchor to pin
pin
required
default:false

Whether to pin the metafield definition.

Anchor to useAsCollectionCondition
useAsCollectionCondition
default:false

Whether the metafield definition can be used as a collection condition.

Anchor to visibleToStorefrontApi
visibleToStorefrontApi
default:null

Whether metafields for the definition are visible using the Storefront API.


Was this section helpful?

The metafield definition that was created.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
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-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!, $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();
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)
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
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$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]);
Hide code
Input variables
Copy
{
  "id": "gid://shopify/StandardMetafieldDefinitionTemplate/2",
  "ownerType": "PRODUCT",
  "pin": false,
  "visibleToStorefrontApi": true
}
Hide code
Response
JSON
{
  "standardMetafieldDefinitionEnable": {
    "createdDefinition": {
      "name": "Care guide",
      "key": "care_guide",
      "namespace": "descriptors",
      "description": "Instructions for taking care of a product or apparel"
    },
    "userErrors": []
  }
}