Anchor to productDeleteImagesproduct
productDeleteImages
mutationDeprecated
Requires access scope. Also: The user must have a permission to remove images from a product.
Removes product images from the product. Use instead.
Anchor to Arguments
Arguments
- •ID!required
This is the ID of the product.
- Anchor to imageIdsimage•
Ids [ID!]!required This is the array of image IDs to delete from the product.
Was this section helpful?
Anchor to ProductDeleteImagesPayload returnsProductDeleteImagesPayload returns
- Anchor to deletedImageIdsdeleted•
Image Ids [ID!]!non-null The array of image IDs to delete.
- Anchor to productproduct•
The product object.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
- Delete an image from a non-existing product
- Delete an image from an existing product
- productDeleteImages reference
Examples
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation productDeleteImages($id: ID!, $imageIds: [ID!]!) {
productDeleteImages(id: $id, imageIds: $imageIds) {
deletedImageIds
product {
id
title
images(first: 5) {
nodes {
id
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"id": "gid://shopify/Product/0",
"imageIds": [
"gid://shopify/ProductImage/183532652"
]
mutation productDeleteImages($id: ID!, $imageIds: [ID!]!) {
productDeleteImages(id: $id, imageIds: $imageIds) {
deletedImageIds
product {
id
title
images(first: 5) {
nodes {
id
}
}
}
userErrors {
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation productDeleteImages($id: ID!, $imageIds: [ID!]!) { productDeleteImages(id: $id, imageIds: $imageIds) { deletedImageIds product { id title images(first: 5) { nodes { id } } } userErrors { field message } } }",
"variables": {
"id": "gid://shopify/Product/0",
"imageIds": [
"gid://shopify/ProductImage/183532652"
]
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation productDeleteImages($id: ID!, $imageIds: [ID!]!) {
productDeleteImages(id: $id, imageIds: $imageIds) {
deletedImageIds
product {
id
title
images(first: 5) {
nodes {
id
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"id": "gid://shopify/Product/0",
"imageIds": [
"gid://shopify/ProductImage/183532652"
]
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation productDeleteImages($id: ID!, $imageIds: [ID!]!) {
productDeleteImages(id: $id, imageIds: $imageIds) {
deletedImageIds
product {
id
title
images(first: 5) {
nodes {
id
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"id": "gid://shopify/Product/0",
"imageIds": [
"gid://shopify/ProductImage/183532652"
]
},
},
});
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 productDeleteImages($id: ID!, $imageIds: [ID!]!) {
productDeleteImages(id: $id, imageIds: $imageIds) {
deletedImageIds
product {
id
title
images(first: 5) {
nodes {
id
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"id": "gid://shopify/Product/0",
"imageIds": ["gid://shopify/ProductImage/183532652"]
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"id": "gid://shopify/Product/0",
"imageIds": [
"gid://shopify/ProductImage/183532652"
]
}
Response
JSON{
"productDeleteImages": {
"deletedImageIds": [],
"product": null,
"userErrors": [
{
"field": [
"id"
],
"message": "Product does not exist"
}
]
}
}