--- title: privateMetafieldDelete - GraphQL Admin description: >- Deletes a private metafield. Private metafields are automatically deleted when the app that created them is uninstalled. api_version: 2024-10 api_name: admin type: mutation api_type: graphql source_url: html: >- https://shopify.dev/docs/api/admin-graphql/2024-10/mutations/privateMetafieldDelete md: >- https://shopify.dev/docs/api/admin-graphql/2024-10/mutations/privateMetafieldDelete.txt --- # private​Metafield​Delete 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). This will be removed in 2025-01. Deletes a private metafield. Private metafields are automatically deleted when the app that created them is uninstalled. ## Arguments * input [Private​Metafield​Delete​Input!](https://shopify.dev/docs/api/admin-graphql/2024-10/input-objects/PrivateMetafieldDeleteInput) required The input fields for the private metafield to delete. *** ## Private​Metafield​Delete​Payload returns * deleted​Private​Metafield​Id [ID](https://shopify.dev/docs/api/admin-graphql/2024-10/scalars/ID) The ID of private metafield that was deleted. * user​Errors [\[User​Error!\]!](https://shopify.dev/docs/api/admin-graphql/2024-10/objects/UserError) non-null The list of errors that occurred from executing the mutation. *** ## Examples * ### Delete a private metafield owned by the Product resource #### Description Use the \`privateMetafieldDelete\` mutation to delete a private metafield. Specify the private metafield that you want to delete by providing its namespace, key, and the ID of the owning resource. #### Query ```graphql mutation privateMetafieldDelete($input: PrivateMetafieldDeleteInput!) { privateMetafieldDelete(input: $input) { deletedPrivateMetafieldId userErrors { field message } } } ``` #### Variables ```json { "input": { "owner": "gid://shopify/Product/20995642", "namespace": "wholesale", "key": "price" } } ``` #### cURL ```bash 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 privateMetafieldDelete($input: PrivateMetafieldDeleteInput!) { privateMetafieldDelete(input: $input) { deletedPrivateMetafieldId userErrors { field message } } }", "variables": { "input": { "owner": "gid://shopify/Product/20995642", "namespace": "wholesale", "key": "price" } } }' ``` #### Remix ```javascript const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation privateMetafieldDelete($input: PrivateMetafieldDeleteInput!) { privateMetafieldDelete(input: $input) { deletedPrivateMetafieldId userErrors { field message } } }`, { variables: { "input": { "owner": "gid://shopify/Product/20995642", "namespace": "wholesale", "key": "price" } }, }, ); const data = await response.json(); ``` #### Ruby ```ruby 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 privateMetafieldDelete($input: PrivateMetafieldDeleteInput!) { privateMetafieldDelete(input: $input) { deletedPrivateMetafieldId userErrors { field message } } } QUERY variables = { "input": { "owner": "gid://shopify/Product/20995642", "namespace": "wholesale", "key": "price" } } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation privateMetafieldDelete($input: PrivateMetafieldDeleteInput!) { privateMetafieldDelete(input: $input) { deletedPrivateMetafieldId userErrors { field message } } }`, "variables": { "input": { "owner": "gid://shopify/Product/20995642", "namespace": "wholesale", "key": "price" } }, }, }); ``` #### Response ```json { "privateMetafieldDelete": { "deletedPrivateMetafieldId": "gid://shopify/PrivateMetafield/1060470839", "userErrors": [] } } ``` * ### Delete a private metafield owned by the Shop resource #### Description Use the \`privateMetafieldDelete\` mutation to delete a private metafield. Specify the private metafield that you want to delete by providing its namespace, key, and the ID of the owning resource. In this example, the private metafield belongs to the \`Shop\` resource, so the owner field can be omitted. #### Query ```graphql mutation privateMetafieldDelete($input: PrivateMetafieldDeleteInput!) { privateMetafieldDelete(input: $input) { deletedPrivateMetafieldId userErrors { field message } } } ``` #### Variables ```json { "input": { "namespace": "private_keys", "key": "fantastic_app" } } ``` #### cURL ```bash 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 privateMetafieldDelete($input: PrivateMetafieldDeleteInput!) { privateMetafieldDelete(input: $input) { deletedPrivateMetafieldId userErrors { field message } } }", "variables": { "input": { "namespace": "private_keys", "key": "fantastic_app" } } }' ``` #### Remix ```javascript const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation privateMetafieldDelete($input: PrivateMetafieldDeleteInput!) { privateMetafieldDelete(input: $input) { deletedPrivateMetafieldId userErrors { field message } } }`, { variables: { "input": { "namespace": "private_keys", "key": "fantastic_app" } }, }, ); const data = await response.json(); ``` #### Ruby ```ruby 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 privateMetafieldDelete($input: PrivateMetafieldDeleteInput!) { privateMetafieldDelete(input: $input) { deletedPrivateMetafieldId userErrors { field message } } } QUERY variables = { "input": { "namespace": "private_keys", "key": "fantastic_app" } } response = client.query(query: query, variables: variables) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation privateMetafieldDelete($input: PrivateMetafieldDeleteInput!) { privateMetafieldDelete(input: $input) { deletedPrivateMetafieldId userErrors { field message } } }`, "variables": { "input": { "namespace": "private_keys", "key": "fantastic_app" } }, }, }); ``` #### Response ```json { "privateMetafieldDelete": { "deletedPrivateMetafieldId": "gid://shopify/PrivateMetafield/1060470838", "userErrors": [] } } ``` * ### privateMetafieldDelete reference [Open in GraphiQL](http://localhost:3457/graphiql?query=mutation%20privateMetafieldDelete\(%24input%3A%20PrivateMetafieldDeleteInput!\)%20%7B%0A%20%20privateMetafieldDelete\(input%3A%20%24input\)%20%7B%0A%20%20%20%20deletedPrivateMetafieldId%0A%20%20%20%20userErrors%20%7B%0A%20%20%20%20%20%20field%0A%20%20%20%20%20%20message%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D\&variables=%7B%0A%20%20%22input%22%3A%20%7B%0A%20%20%20%20%22owner%22%3A%20%22gid%3A%2F%2Fshopify%2FProduct%2F20995642%22%2C%0A%20%20%20%20%22namespace%22%3A%20%22wholesale%22%2C%0A%20%20%20%20%22key%22%3A%20%22price%22%0A%20%20%7D%0A%7D) ```javascript const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation privateMetafieldDelete($input: PrivateMetafieldDeleteInput!) { privateMetafieldDelete(input: $input) { deletedPrivateMetafieldId userErrors { field message } } }`, { variables: { "input": { "owner": "gid://shopify/Product/20995642", "namespace": "wholesale", "key": "price" } }, }, ); const data = await response.json(); ``` ## Input variables JSON ```json { "input": { "owner": "gid://shopify/Product/20995642", "namespace": "wholesale", "key": "price" } } ``` ## Response JSON ```json { "privateMetafieldDelete": { "deletedPrivateMetafieldId": "gid://shopify/PrivateMetafield/1060470839", "userErrors": [] } } ```