Anchor to privateMetafieldUpsertprivate
private Metafield Upsert
mutation
Deprecated. Metafields created using a reserved namespace are private by default. See our guide for [migrating private metafields](https://shopify.dev/docs/apps/custom-data/metafields/migrate-private-metafields).
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.
Anchor to Arguments
Arguments
- Anchor to inputinput•Private
Metafield Input!required Specifies the input fields for the private metafield.
Was this section helpful?
- 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.
Was this section helpful?
- Create a private metafield for a resource
- Update a private metafield
- privateMetafieldUpsert reference
Examples
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();
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-10/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)
Input variables
JSON{
"input": {
"owner": "gid://shopify/Product/632910392",
"namespace": "wholesale",
"key": "price",
"valueInput": {
"value": "5.00",
"valueType": "STRING"
}
}
}
Response
JSON{
"privateMetafieldUpsert": {
"privateMetafield": {
"id": "gid://shopify/PrivateMetafield/1060470848",
"namespace": "wholesale",
"key": "price",
"value": "5.00",
"valueType": "STRING"
},
"userErrors": []
}
}