Anchor to productImageUpdateproduct
productImageUpdate
mutationDeprecated
Requires access scope. Also: The user must have a permission to update an image of a product.
Updates an image of a product. Use instead.
Anchor to Arguments
Arguments
- Anchor to imageimage•Image
Input! required Image to be updated.
- Anchor to productIdproduct•
Id ID!required The ID of the product on which to update the image.
Was this section helpful?
Anchor to ProductImageUpdatePayload returnsProductImageUpdatePayload returns
- Anchor to imageimage•
The image that has been updated.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
- Update a product's image
- Update an image of a non-existent product
- Update the product with a non-existent image
- productImageUpdate reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation productImageUpdate($productId: ID!, $image: ImageInput!) {6 productImageUpdate(productId: $productId, image: $image) {7 image {8 id9 altText10 src11 }12 userErrors {13 field14 message15 }16 }17 }`,18 {19 variables: {20 "productId": "gid://shopify/Product/108828309",21 "image": {22 "id": "gid://shopify/ProductImage/183532652",23 "altText": "New image description.",24 "src": "https://cdn.shopify.com/s/files/1/2637/1970/products/draft58.jpg?v=1726103124"25 }26 },27 },28);2930const data = await response.json();31
mutation productImageUpdate($productId: ID!, $image: ImageInput!) {
productImageUpdate(productId: $productId, image: $image) {
image {
id
altText
src
}
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 productImageUpdate($productId: ID!, $image: ImageInput!) { productImageUpdate(productId: $productId, image: $image) { image { id altText src } userErrors { field message } } }",
"variables": {
"productId": "gid://shopify/Product/108828309",
"image": {
"id": "gid://shopify/ProductImage/183532652",
"altText": "New image description.",
"src": "https://cdn.shopify.com/s/files/1/2637/1970/products/draft58.jpg?v=1726103124"
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation productImageUpdate($productId: ID!, $image: ImageInput!) {
productImageUpdate(productId: $productId, image: $image) {
image {
id
altText
src
}
userErrors {
field
message
}
}
}`,
{
variables: {
"productId": "gid://shopify/Product/108828309",
"image": {
"id": "gid://shopify/ProductImage/183532652",
"altText": "New image description.",
"src": "https://cdn.shopify.com/s/files/1/2637/1970/products/draft58.jpg?v=1726103124"
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation productImageUpdate($productId: ID!, $image: ImageInput!) {
productImageUpdate(productId: $productId, image: $image) {
image {
id
altText
src
}
userErrors {
field
message
}
}
}`,
"variables": {
"productId": "gid://shopify/Product/108828309",
"image": {
"id": "gid://shopify/ProductImage/183532652",
"altText": "New image description.",
"src": "https://cdn.shopify.com/s/files/1/2637/1970/products/draft58.jpg?v=1726103124"
}
},
},
});
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 productImageUpdate($productId: ID!, $image: ImageInput!) {
productImageUpdate(productId: $productId, image: $image) {
image {
id
altText
src
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"productId": "gid://shopify/Product/108828309",
"image": {
"id": "gid://shopify/ProductImage/183532652",
"altText": "New image description.",
"src": "https://cdn.shopify.com/s/files/1/2637/1970/products/draft58.jpg?v=1726103124"
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "productId": "gid://shopify/Product/108828309",3 "image": {4 "id": "gid://shopify/ProductImage/183532652",5 "altText": "New image description.",6 "src": "https://cdn.shopify.com/s/files/1/2637/1970/products/draft58.jpg?v=1726103124"7 }8}
Response
JSON1{2 "productImageUpdate": {3 "image": {4 "id": "gid://shopify/ProductImage/183532652",5 "altText": "New image description.",6 "src": "https://cdn.shopify.com/s/files/1/2637/1970/products/draft58.jpg?v=1726103124"7 },8 "userErrors": []9 }10}