private Metafield Upsertmutation deprecated
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
Specifies the input fields for the private metafield.
PrivateMetafieldUpsertPayload returns
The private metafield that was created or updated.
The list of errors that occurred from executing the mutation.
Code examples for MUTATION: privateMetafieldUpsert
Query Reference for MUTATION: privateMetafieldUpsert
"mutation privateMetafieldUpsert($input: PrivateMetafieldInput!) {\n privateMetafieldUpsert(input: $input) {\n privateMetafield {\n # PrivateMetafield fields\n }\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: privateMetafieldUpsert
"{\n \"input\": {\n \"key\": \"<your-key>\",\n \"namespace\": \"<your-namespace>\",\n \"owner\": \"gid://shopify/<objectName>/10079785100\",\n \"valueInput\": {\n \"value\": \"<your-value>\",\n \"valueType\": \"INTEGER\"\n }\n }\n}"
Schema Reference for MUTATION: privateMetafieldUpsert
"input PrivateMetafieldInput {\n key: String!\n namespace: String!\n owner: ID\n valueInput: PrivateMetafieldValueInput!\n}\n\ninput PrivateMetafieldValueInput {\n value: String!\n valueType: PrivateMetafieldValueType!\n}\n"
Display Examples for MUTATION: privateMetafieldUpsert
[ { "example": { "type_name": "privatemetafieldupsert", "title": "Update a private metafield", "description": "You can update a private metafield's value and value type by using the `privateMetafieldUpsert` mutation.\nAs part of the input, specify the owning resource by its ID, and specify the private metafield by its namespace and key.\nIn this example, the private metafield belongs to the `Shop` resource, so the owner field can be omitted.\n", "query_string": "mutation privateMetafieldUpsert($input: PrivateMetafieldInput!) {\n privateMetafieldUpsert(input: $input) {\n privateMetafield {\n id\n namespace\n key\n value\n valueType\n }\n userErrors {\n field\n message\n }\n }\n}", "variables": { "input": { "namespace": "private_keys", "key": "fantastic_app", "valueInput": { "value": "TA710SP", "valueType": "STRING" } } }, "response": { "data": { "privateMetafieldUpsert": { "privateMetafield": { "id": "gid://shopify/PrivateMetafield/1060470837", "namespace": "private_keys", "key": "fantastic_app", "value": "TA710SP", "valueType": "STRING" }, "userErrors": [] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/content/metafields/test/unit/graph_api/admin/mutations/private_metafield_upsert_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation privateMetafieldUpsert($input: PrivateMetafieldInput!) { privateMetafieldUpsert(input: $input) { privateMetafield { id namespace key value valueType } userErrors { field message } } }\",\n \"variables\": {\n \"input\": {\n \"namespace\": \"private_keys\",\n \"key\": \"fantastic_app\",\n \"valueInput\": {\n \"value\": \"TA710SP\",\n \"valueType\": \"STRING\"\n }\n }\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation privateMetafieldUpsert($input: PrivateMetafieldInput!) {\n privateMetafieldUpsert(input: $input) {\n privateMetafield {\n id\n namespace\n key\n value\n valueType\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"namespace\": \"private_keys\",\n \"key\": \"fantastic_app\",\n \"valueInput\": {\n \"value\": \"TA710SP\",\n \"valueType\": \"STRING\"\n }\n }\n },\n },\n);\n\nconst data = await response.json();\n", "ruby_example": "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation privateMetafieldUpsert($input: PrivateMetafieldInput!) {\n privateMetafieldUpsert(input: $input) {\n privateMetafield {\n id\n namespace\n key\n value\n valueType\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"namespace\": \"private_keys\",\n \"key\": \"fantastic_app\",\n \"valueInput\": {\n \"value\": \"TA710SP\",\n \"valueType\": \"STRING\"\n }\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation privateMetafieldUpsert($input: PrivateMetafieldInput!) {\n privateMetafieldUpsert(input: $input) {\n privateMetafield {\n id\n namespace\n key\n value\n valueType\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"namespace\": \"private_keys\",\n \"key\": \"fantastic_app\",\n \"valueInput\": {\n \"value\": \"TA710SP\",\n \"valueType\": \"STRING\"\n }\n }\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation privateMetafieldUpsert($input: PrivateMetafieldInput!) {\n privateMetafieldUpsert(input: $input) {\n privateMetafield {\n id\n namespace\n key\n value\n valueType\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY;\n\n$variables = [\n \"input\" => [\n \"namespace\" => \"private_keys\",\n \"key\" => \"fantastic_app\",\n \"valueInput\" => [\n \"value\" => \"TA710SP\",\n \"valueType\" => \"STRING\",\n ],\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "input", "description": "Specifies the input fields for the private metafield.", "type": { "kind": "INPUT_OBJECT", "name": "PrivateMetafieldInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "PrivateMetafieldInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "input", "argValue": " {\"namespace\":\"private_keys\",\"key\":\"fantastic_app\",\"valueInput\":{\"value\":\"TA710SP\",\"valueType\":\"STRING\"}}", "typeKind": "MUTATION" } ] } ]