Anchor to section titled 'undefined'

metafieldDefinitionUpdate
mutation

Requires API client to have access to the namespace and the resource type associated with the metafield definition.

Updates a metafield definition.


The input fields for the metafield definition update.


Was this section helpful?

The metafield definition that was updated.

The list of errors that occurred from executing the mutation.

The asynchronous job updating the metafield definition's validation_status.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation UpdateMetafieldDefinition($definition: MetafieldDefinitionUpdateInput!) {
  metafieldDefinitionUpdate(definition: $definition) {
    updatedDefinition {
      id
      name
    }
    userErrors {
      field
      message
      code
    }
  }
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation UpdateMetafieldDefinition($definition: MetafieldDefinitionUpdateInput!) { metafieldDefinitionUpdate(definition: $definition) { updatedDefinition { id name } userErrors { field message code } } }",
 "variables": {
    "definition": {
      "name": "Pizza size (inches)",
      "namespace": "bakery",
      "key": "pizza_size",
      "ownerType": "PRODUCT"
    }
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation UpdateMetafieldDefinition($definition: MetafieldDefinitionUpdateInput!) {
    metafieldDefinitionUpdate(definition: $definition) {
      updatedDefinition {
        id
        name
      }
      userErrors {
        field
        message
        code
      }
    }
  }`,
  {
    variables: {
      "definition": {
        "name": "Pizza size (inches)",
        "namespace": "bakery",
        "key": "pizza_size",
        "ownerType": "PRODUCT"
      }
    },
  },
);

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 UpdateMetafieldDefinition($definition: MetafieldDefinitionUpdateInput!) {
    metafieldDefinitionUpdate(definition: $definition) {
      updatedDefinition {
        id
        name
      }
      userErrors {
        field
        message
        code
      }
    }
  }
QUERY

variables = {
  "definition": {
    "name": "Pizza size (inches)",
    "namespace": "bakery",
    "key": "pizza_size",
    "ownerType": "PRODUCT"
  }
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation UpdateMetafieldDefinition($definition: MetafieldDefinitionUpdateInput!) {
      metafieldDefinitionUpdate(definition: $definition) {
        updatedDefinition {
          id
          name
        }
        userErrors {
          field
          message
          code
        }
      }
    }`,
    "variables": {
      "definition": {
        "name": "Pizza size (inches)",
        "namespace": "bakery",
        "key": "pizza_size",
        "ownerType": "PRODUCT"
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation UpdateMetafieldDefinition($definition: MetafieldDefinitionUpdateInput!) {
    metafieldDefinitionUpdate(definition: $definition) {
      updatedDefinition {
        id
        name
      }
      userErrors {
        field
        message
        code
      }
    }
  }
QUERY;

$variables = [
  "definition" => [
    "name" => "Pizza size (inches)",
    "namespace" => "bakery",
    "key" => "pizza_size",
    "ownerType" => "PRODUCT",
  ],
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "definition": {
    "name": "Pizza size (inches)",
    "namespace": "bakery",
    "key": "pizza_size",
    "ownerType": "PRODUCT"
  }
}
Hide code
Response
JSON
{
  "metafieldDefinitionUpdate": {
    "updatedDefinition": {
      "id": "gid://shopify/MetafieldDefinition/1071456170",
      "name": "Pizza size (inches)"
    },
    "userErrors": []
  }
}