Anchor to productDeleteMediaproduct
productDeleteMedia
mutationDeprecated
Requires access scope. Also: The user must have a permission to delete media from a product.
Deletes media for a product. Use instead.
Anchor to Arguments
Arguments
- Anchor to mediaIdsmedia•
Ids [ID!]!required The media IDs to be deleted.
- Anchor to productIdproduct•
Id ID!required Specifies the product ID from which the media will be deleted.
Was this section helpful?
Anchor to ProductDeleteMediaPayload returnsProductDeleteMediaPayload returns
- Anchor to deletedMediaIdsdeleted•
Media Ids List of media IDs which were deleted.
- Anchor to deletedProductImageIdsdeleted•
Product Image Ids List of product image IDs which were deleted.
- Anchor to mediaUserErrorsmedia•
User Errors [MediaUser non-nullError!]! The list of errors that occurred from executing the mutation.
- Anchor to productproduct•
The product associated with the deleted media.
- Anchor to userErrorsuser•
Errors The list of errors that occurred from executing the mutation.
Was this section helpful?
- Delete existing and non-existing media from a product
- Delete media from a non-existent product
- Delete media from an existing product
- Delete non-existing media from an existing product
- Remove an existing Product Image
- productDeleteMedia reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation productDeleteMedia($mediaIds: [ID!]!, $productId: ID!) {6 productDeleteMedia(mediaIds: $mediaIds, productId: $productId) {7 deletedMediaIds8 deletedProductImageIds9 mediaUserErrors {10 field11 message12 }13 product {14 id15 title16 media(first: 5) {17 nodes {18 alt19 mediaContentType20 status21 }22 }23 }24 }25 }`,26 {27 variables: {28 "mediaIds": [29 "gid://shopify/Video/-1",30 "gid://shopify/Video/723685877"31 ],32 "productId": "gid://shopify/Product/108828309"33 },34 },35);3637const data = await response.json();38
mutation productDeleteMedia($mediaIds: [ID!]!, $productId: ID!) {
productDeleteMedia(mediaIds: $mediaIds, productId: $productId) {
deletedMediaIds
deletedProductImageIds
mediaUserErrors {
field
message
}
product {
id
title
media(first: 5) {
nodes {
alt
mediaContentType
status
}
}
}
}
}
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 productDeleteMedia($mediaIds: [ID!]!, $productId: ID!) { productDeleteMedia(mediaIds: $mediaIds, productId: $productId) { deletedMediaIds deletedProductImageIds mediaUserErrors { field message } product { id title media(first: 5) { nodes { alt mediaContentType status } } } } }",
"variables": {
"mediaIds": [
"gid://shopify/Video/-1",
"gid://shopify/Video/723685877"
],
"productId": "gid://shopify/Product/108828309"
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation productDeleteMedia($mediaIds: [ID!]!, $productId: ID!) {
productDeleteMedia(mediaIds: $mediaIds, productId: $productId) {
deletedMediaIds
deletedProductImageIds
mediaUserErrors {
field
message
}
product {
id
title
media(first: 5) {
nodes {
alt
mediaContentType
status
}
}
}
}
}`,
{
variables: {
"mediaIds": [
"gid://shopify/Video/-1",
"gid://shopify/Video/723685877"
],
"productId": "gid://shopify/Product/108828309"
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation productDeleteMedia($mediaIds: [ID!]!, $productId: ID!) {
productDeleteMedia(mediaIds: $mediaIds, productId: $productId) {
deletedMediaIds
deletedProductImageIds
mediaUserErrors {
field
message
}
product {
id
title
media(first: 5) {
nodes {
alt
mediaContentType
status
}
}
}
}
}`,
"variables": {
"mediaIds": [
"gid://shopify/Video/-1",
"gid://shopify/Video/723685877"
],
"productId": "gid://shopify/Product/108828309"
},
},
});
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 productDeleteMedia($mediaIds: [ID!]!, $productId: ID!) {
productDeleteMedia(mediaIds: $mediaIds, productId: $productId) {
deletedMediaIds
deletedProductImageIds
mediaUserErrors {
field
message
}
product {
id
title
media(first: 5) {
nodes {
alt
mediaContentType
status
}
}
}
}
}
QUERY
variables = {
"mediaIds": ["gid://shopify/Video/-1", "gid://shopify/Video/723685877"],
"productId": "gid://shopify/Product/108828309"
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "mediaIds": [3 "gid://shopify/Video/-1",4 "gid://shopify/Video/723685877"5 ],6 "productId": "gid://shopify/Product/108828309"7}
Response
JSON1{2 "productDeleteMedia": {3 "deletedMediaIds": null,4 "deletedProductImageIds": null,5 "mediaUserErrors": [6 {7 "field": [8 "mediaIds"9 ],10 "message": "Media id gid://shopify/Video/-1 does not exist"11 }12 ],13 "product": {14 "id": "gid://shopify/Product/108828309",15 "title": "Draft",16 "media": {17 "nodes": [18 {19 "alt": "This is a video",20 "mediaContentType": "EXTERNAL_VIDEO",21 "status": "READY"22 },23 {24 "alt": "This is a video",25 "mediaContentType": "VIDEO",26 "status": "READY"27 },28 {29 "alt": "This is a 3d Model",30 "mediaContentType": "MODEL_3D",31 "status": "READY"32 },33 {34 "alt": "",35 "mediaContentType": "IMAGE",36 "status": "READY"37 },38 {39 "alt": "",40 "mediaContentType": "IMAGE",41 "status": "READY"42 }43 ]44 }45 }46 }47}