Anchor to section titled 'undefined'

metafieldStorefrontVisibilityCreate
mutation
deprecated

Requires API client to have access to the owner type and namespace.

Creates a MetafieldStorefrontVisibility record to make all metafields that belong to the specified resource and have the established namespace and key combination visible in the Storefront API. This mutation will be removed in a future version. Use the metafieldDefinitionCreate or metafieldDefinitionUpdate mutations with access.storefront set instead.


Specifies the input fields for a MetafieldStorefrontVisibility record.


Was this section helpful?

The MetafieldStorefrontVisibility that was created.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation CreateMetafieldStorefrontVisibility($input: MetafieldStorefrontVisibilityInput!) {
  metafieldStorefrontVisibilityCreate(input: $input) {
    metafieldStorefrontVisibility {
      namespace
      key
    }
    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 CreateMetafieldStorefrontVisibility($input: MetafieldStorefrontVisibilityInput!) { metafieldStorefrontVisibilityCreate(input: $input) { metafieldStorefrontVisibility { namespace key } userErrors { field message } } }",
 "variables": {
    "input": {
      "namespace": "bakery",
      "key": "ingredients",
      "ownerType": "PRODUCT"
    }
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation CreateMetafieldStorefrontVisibility($input: MetafieldStorefrontVisibilityInput!) {
    metafieldStorefrontVisibilityCreate(input: $input) {
      metafieldStorefrontVisibility {
        namespace
        key
      }
      userErrors {
        field
        message
      }
    }
  }`,
  {
    variables: {
      "input": {
        "namespace": "bakery",
        "key": "ingredients",
        "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 CreateMetafieldStorefrontVisibility($input: MetafieldStorefrontVisibilityInput!) {
    metafieldStorefrontVisibilityCreate(input: $input) {
      metafieldStorefrontVisibility {
        namespace
        key
      }
      userErrors {
        field
        message
      }
    }
  }
QUERY

variables = {
  "input": {
    "namespace": "bakery",
    "key": "ingredients",
    "ownerType": "PRODUCT"
  }
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation CreateMetafieldStorefrontVisibility($input: MetafieldStorefrontVisibilityInput!) {
      metafieldStorefrontVisibilityCreate(input: $input) {
        metafieldStorefrontVisibility {
          namespace
          key
        }
        userErrors {
          field
          message
        }
      }
    }`,
    "variables": {
      "input": {
        "namespace": "bakery",
        "key": "ingredients",
        "ownerType": "PRODUCT"
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation CreateMetafieldStorefrontVisibility($input: MetafieldStorefrontVisibilityInput!) {
    metafieldStorefrontVisibilityCreate(input: $input) {
      metafieldStorefrontVisibility {
        namespace
        key
      }
      userErrors {
        field
        message
      }
    }
  }
QUERY;

$variables = [
  "input" => [
    "namespace" => "bakery",
    "key" => "ingredients",
    "ownerType" => "PRODUCT",
  ],
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "input": {
    "namespace": "bakery",
    "key": "ingredients",
    "ownerType": "PRODUCT"
  }
}
Hide code
Response
JSON
{
  "metafieldStorefrontVisibilityCreate": {
    "metafieldStorefrontVisibility": {
      "namespace": "bakery",
      "key": "ingredients"
    },
    "userErrors": []
  }
}