--- title: commentDelete - GraphQL Admin description: Deletes a comment. api_version: unstable api_name: admin source_url: html: https://shopify.dev/docs/api/admin-graphql/unstable/mutations/commentdelete md: https://shopify.dev/docs/api/admin-graphql/unstable/mutations/commentdelete.md --- # comment​Delete mutation Requires Any of `write_content`, `write_online_store_pages` access scopes. Deletes a comment. ## Arguments * id [ID!](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/ID) required The ID of the comment to be deleted. *** ## Comment​Delete​Payload returns * deleted​Comment​Id [ID](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/ID) The ID of the comment that was deleted. * user​Errors [\[Comment​Delete​User​Error!\]!](https://shopify.dev/docs/api/admin-graphql/unstable/objects/CommentDeleteUserError) non-null The list of errors that occurred from executing the mutation. *** ## Examples * ### Attempting to delete a non-existent comment #### Description Attempting to delete a comment that does not exist returns a not found error #### Query ```graphql mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } } ``` #### Variables ```json { "id": "gid://shopify/Comment/9001" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } }", "variables": { "id": "gid://shopify/Comment/9001" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } }`, { variables: { "id": "gid://shopify/Comment/9001" }, }, ); const json = await response.json(); return json.data; } ``` #### 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 DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } } QUERY variables = { "id": "gid://shopify/Comment/9001" } 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 DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } }`, "variables": { "id": "gid://shopify/Comment/9001" }, }, }); ``` #### Response ```json { "commentDelete": { "deletedCommentId": null, "userErrors": [ { "field": [ "id" ], "message": "Comment does not exist" } ] } } ``` * ### Deleting a comment with proper permissions #### Description Deleting a comment with the necessary merchant access scopes succeeds and deletes the comment #### Query ```graphql mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } } ``` #### Variables ```json { "id": "gid://shopify/Comment/757536350" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } }", "variables": { "id": "gid://shopify/Comment/757536350" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } }`, { variables: { "id": "gid://shopify/Comment/757536350" }, }, ); const json = await response.json(); return json.data; } ``` #### 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 DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } } QUERY variables = { "id": "gid://shopify/Comment/757536350" } 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 DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } }`, "variables": { "id": "gid://shopify/Comment/757536350" }, }, }); ``` #### Response ```json { "commentDelete": { "deletedCommentId": "gid://shopify/Comment/757536350", "userErrors": [] } } ``` * ### Failing to delete a comment due to missing access scopes #### Description Attempting to delete a comment without the necessary \`write\_content\` or \`write\_online\_store\_pages\` access scope results in an access denied error #### Query ```graphql mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } } ``` #### Variables ```json { "id": "gid://shopify/Comment/757536350" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } }", "variables": { "id": "gid://shopify/Comment/757536350" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } }`, { variables: { "id": "gid://shopify/Comment/757536350" }, }, ); const json = await response.json(); return json.data; } ``` #### 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 DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } } QUERY variables = { "id": "gid://shopify/Comment/757536350" } 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 DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } }`, "variables": { "id": "gid://shopify/Comment/757536350" }, }, }); ``` #### Response ```json { "commentDelete": null } ``` * ### Removes a comment #### Query ```graphql mutation CommentDelete($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { code field message } } } ``` #### Variables ```json { "id": "gid://shopify/Comment/757536350" } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation CommentDelete($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { code field message } } }", "variables": { "id": "gid://shopify/Comment/757536350" } }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation CommentDelete($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { code field message } } }`, { variables: { "id": "gid://shopify/Comment/757536350" }, }, ); const json = await response.json(); return json.data; } ``` #### 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 CommentDelete($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { code field message } } } QUERY variables = { "id": "gid://shopify/Comment/757536350" } 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 CommentDelete($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { code field message } } }`, "variables": { "id": "gid://shopify/Comment/757536350" }, }, }); ``` #### Response ```json { "commentDelete": { "deletedCommentId": "gid://shopify/Comment/757536350", "userErrors": [] } } ``` * ### commentDelete reference [Open in GraphiQL](http://localhost:3457/graphiql?query=mutation%20DeleteComment\(%24id%3A%20ID!\)%20%7B%0A%20%20commentDelete\(id%3A%20%24id\)%20%7B%0A%20%20%20%20deletedCommentId%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%22id%22%3A%20%22gid%3A%2F%2Fshopify%2FComment%2F9001%22%0A%7D) ##### GQL ```graphql mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } } ``` ##### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } }", "variables": { "id": "gid://shopify/Comment/9001" } }' ``` ##### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } }`, { variables: { "id": "gid://shopify/Comment/9001" }, }, ); const json = await response.json(); return json.data; } ``` ##### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } }`, "variables": { "id": "gid://shopify/Comment/9001" }, }, }); ``` ##### 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 DeleteComment($id: ID!) { commentDelete(id: $id) { deletedCommentId userErrors { field message } } } QUERY variables = { "id": "gid://shopify/Comment/9001" } response = client.query(query: query, variables: variables) ``` ## Input variables JSON ```json { "id": "gid://shopify/Comment/9001" } ``` ## Response JSON ```json { "commentDelete": { "deletedCommentId": null, "userErrors": [ { "field": [ "id" ], "message": "Comment does not exist" } ] } } ```