privateMetafieldUpsert
Creates or updates a private metafield. Use private metafields when you don't want the metafield data to be accessible by merchants or other apps. 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. Metafields created using a reserved namespace are private by default. See our guide for migrating private metafields.
Arguments
- Anchor to inputinput•Private
Metafield requiredInput! Specifies the input fields for the private metafield.
Anchor to PrivateMetafieldUpsertPayload returnsPrivateMetafieldUpsertPayload returns
- Anchor to privateMetafieldprivate•
Metafield The private metafield that was created or updated.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
- Create a private metafield for a resource
- Create a private metafield from the resources' mutations
- Update a private metafield
- Update a private metafield using the update mutation for the owning resource
- privateMetafieldUpsert reference
Examples
mutation privateMetafieldUpsert($input: PrivateMetafieldInput!) {
privateMetafieldUpsert(input: $input) {
privateMetafield {
id
namespace
key
value
valueType
}
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 privateMetafieldUpsert($input: PrivateMetafieldInput!) { privateMetafieldUpsert(input: $input) { privateMetafield { id namespace key value valueType } userErrors { field message } } }",
"variables": {
"input": {
"owner": "gid://shopify/Product/632910392",
"namespace": "wholesale",
"key": "price",
"valueInput": {
"value": "5.00",
"valueType": "STRING"
}
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation privateMetafieldUpsert($input: PrivateMetafieldInput!) {
privateMetafieldUpsert(input: $input) {
privateMetafield {
id
namespace
key
value
valueType
}
userErrors {
field
message
}
}
}`,
{
variables: {
"input": {
"owner": "gid://shopify/Product/632910392",
"namespace": "wholesale",
"key": "price",
"valueInput": {
"value": "5.00",
"valueType": "STRING"
}
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation privateMetafieldUpsert($input: PrivateMetafieldInput!) {
privateMetafieldUpsert(input: $input) {
privateMetafield {
id
namespace
key
value
valueType
}
userErrors {
field
message
}
}
}`,
"variables": {
"input": {
"owner": "gid://shopify/Product/632910392",
"namespace": "wholesale",
"key": "price",
"valueInput": {
"value": "5.00",
"valueType": "STRING"
}
}
},
},
});
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 privateMetafieldUpsert($input: PrivateMetafieldInput!) {
privateMetafieldUpsert(input: $input) {
privateMetafield {
id
namespace
key
value
valueType
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"input": {
"owner": "gid://shopify/Product/632910392",
"namespace": "wholesale",
"key": "price",
"valueInput": {
"value": "5.00",
"valueType": "STRING"
}
}
}
response = client.query(query: query, variables: variables)