Anchor to section titled 'undefined'

productDeleteImages
mutation
deprecated

Requires write_products access scope. Also: The user must have a permission to remove images from a product.

Removes product images from the product. Use productDeleteMedia instead.


Anchor to id
id
required

This is the ID of the product.

Anchor to imageIds
imageIds
required

This is the array of image IDs to delete from the product.


Was this section helpful?

The array of image IDs to delete.

The product object.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
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-01/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();
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)
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"
      ]
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$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]);
Hide code
Input variables
Copy
{
  "id": "gid://shopify/Product/0",
  "imageIds": [
    "gid://shopify/ProductImage/183532652"
  ]
}
Hide code
Response
JSON
{
  "productDeleteImages": {
    "deletedImageIds": [],
    "product": null,
    "userErrors": [
      {
        "field": [
          "id"
        ],
        "message": "Product does not exist"
      }
    ]
  }
}