Anchor to productDeleteproduct
productDelete
mutation
Requires access scope. Also: The user must have a permission to delete products.
Deletes a product, including all associated variants and media.
As of API version 2023-01
, if you need to delete a large product, such as one that has many
variants
that are active at several
locations,
you may encounter timeout errors. To avoid these timeout errors, you can instead use the asynchronous
ProductDeleteAsync
mutation.
Anchor to Arguments
Arguments
- Anchor to inputinput•Product
Delete requiredInput! Specifies the product to delete by its ID.
- Anchor to synchronoussynchronous•BooleanDefault:true
Specifies whether or not to run the mutation synchronously.
Was this section helpful?
Anchor to ProductDeletePayload returnsProductDeletePayload returns
- Anchor to deletedProductIddeleted•
Product Id The ID of the deleted product.
- Anchor to productDeleteOperationproduct•
Delete Operation The product delete operation, returned when run in asynchronous mode.
- Anchor to shopshop•Shop!non-null
The shop associated with the product.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
- Delete a non-existent product
- Delete a product
- Delete a product asynchronously and return a product delete operation
- productDelete reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation {6 productDelete(input: {id: "gid://shopify/Product/-1"}) {7 deletedProductId8 userErrors {9 field10 message11 }12 }13 }`,14);1516const data = await response.json();17
mutation {
productDelete(input: {id: "gid://shopify/Product/-1"}) {
deletedProductId
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 { productDelete(input: {id: \"gid://shopify/Product/-1\"}) { deletedProductId userErrors { field message } } }"
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation {
productDelete(input: {id: "gid://shopify/Product/-1"}) {
deletedProductId
userErrors {
field
message
}
}
}`,
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: `mutation {
productDelete(input: {id: "gid://shopify/Product/-1"}) {
deletedProductId
userErrors {
field
message
}
}
}`,
});
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 {
productDelete(input: {id: "gid://shopify/Product/-1"}) {
deletedProductId
userErrors {
field
message
}
}
}
QUERY
response = client.query(query: query)
Response
JSON1{2 "productDelete": {3 "deletedProductId": null,4 "userErrors": [5 {6 "field": [7 "id"8 ],9 "message": "Product does not exist"10 }11 ]12 }13}