privateMetafield
Returns a private metafield by ID. Private metafields are accessible only by the application that created them. Metafields created using a reserved namespace are private by default. See our guide for migrating private metafields.
Anchor to Possible returnsPossible returns
- Anchor to PrivateMetafieldPrivate•
Metafield Private metafields represent custom metadata that is attached to a resource. Private metafields are accessible only by the application that created them and only from the GraphQL Admin API.
An application can create a maximum of 10 private metafields per shop resource.
Private metafields are deprecated. Metafields created using a reserved namespace are private by default. See our guide for migrating private metafields.
Retrieve a private metafield by its ID
query {
privateMetafield(id: "gid://shopify/PrivateMetafield/1060470840") {
id
key
namespace
value
}
}
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": "query { privateMetafield(id: \"gid://shopify/PrivateMetafield/1060470840\") { id key namespace value } }"
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
query {
privateMetafield(id: "gid://shopify/PrivateMetafield/1060470840") {
id
key
namespace
value
}
}`,
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: `query {
privateMetafield(id: "gid://shopify/PrivateMetafield/1060470840") {
id
key
namespace
value
}
}`,
});
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
query {
privateMetafield(id: "gid://shopify/PrivateMetafield/1060470840") {
id
key
namespace
value
}
}
QUERY
response = client.query(query: query)