Anchor to productUpdateproduct
productUpdate
mutation
Requires access scope. Also: The user must have a permission to update products.
Updates a product.
For versions 2024-01
and older:
If you update a product and only include some variants in the update,
then any variants not included will be deleted.
To safely manage variants without the risk of deleting excluded variants, use productVariantsBulkUpdate.
If you want to update a single variant, then use productVariantUpdate.
Anchor to Arguments
Arguments
- Anchor to mediamedia•
List of new media to be added to the product.
- Anchor to productproduct•
The updated properties for a product.
- Anchor to inputinput•Product
Input Deprecated The updated properties for a product. Deprecated as of
2024-10
.Use
product
argument instead.
Was this section helpful?
Anchor to ProductUpdatePayload returnsProductUpdatePayload returns
- Anchor to productproduct•
The updated product object.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
- Add new media to an existing product
- Create a new metafield and update another on an existing product
- Update a product's title and return the product ID
- Updates a product
- productUpdate reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation UpdateProductWithNewMedia($input: ProductInput!, $media: [CreateMediaInput!]) {6 productUpdate(input: $input, media: $media) {7 product {8 id9 media(first: 10) {10 nodes {11 alt12 mediaContentType13 preview {14 status15 }16 }17 }18 }19 userErrors {20 field21 message22 }23 }24 }`,25 {26 variables: {27 "input": {28 "id": "gid://shopify/Product/912855135"29 },30 "media": [31 {32 "originalSource": "https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png",33 "alt": "Gray helmet for bikers",34 "mediaContentType": "IMAGE"35 },36 {37 "originalSource": "https://www.youtube.com/watch?v=4L8VbGRibj8&list=PLlMkWQ65HlcEoPyG9QayqEaAu0ftj0MMz",38 "alt": "Testing helmet resistance against impacts",39 "mediaContentType": "EXTERNAL_VIDEO"40 }41 ]42 },43 },44);4546const data = await response.json();47
mutation UpdateProductWithNewMedia($input: ProductInput!, $media: [CreateMediaInput!]) {
productUpdate(input: $input, media: $media) {
product {
id
media(first: 10) {
nodes {
alt
mediaContentType
preview {
status
}
}
}
}
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 UpdateProductWithNewMedia($input: ProductInput!, $media: [CreateMediaInput!]) { productUpdate(input: $input, media: $media) { product { id media(first: 10) { nodes { alt mediaContentType preview { status } } } } userErrors { field message } } }",
"variables": {
"input": {
"id": "gid://shopify/Product/912855135"
},
"media": [
{
"originalSource": "https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png",
"alt": "Gray helmet for bikers",
"mediaContentType": "IMAGE"
},
{
"originalSource": "https://www.youtube.com/watch?v=4L8VbGRibj8&list=PLlMkWQ65HlcEoPyG9QayqEaAu0ftj0MMz",
"alt": "Testing helmet resistance against impacts",
"mediaContentType": "EXTERNAL_VIDEO"
}
]
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation UpdateProductWithNewMedia($input: ProductInput!, $media: [CreateMediaInput!]) {
productUpdate(input: $input, media: $media) {
product {
id
media(first: 10) {
nodes {
alt
mediaContentType
preview {
status
}
}
}
}
userErrors {
field
message
}
}
}`,
{
variables: {
"input": {
"id": "gid://shopify/Product/912855135"
},
"media": [
{
"originalSource": "https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png",
"alt": "Gray helmet for bikers",
"mediaContentType": "IMAGE"
},
{
"originalSource": "https://www.youtube.com/watch?v=4L8VbGRibj8&list=PLlMkWQ65HlcEoPyG9QayqEaAu0ftj0MMz",
"alt": "Testing helmet resistance against impacts",
"mediaContentType": "EXTERNAL_VIDEO"
}
]
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation UpdateProductWithNewMedia($input: ProductInput!, $media: [CreateMediaInput!]) {
productUpdate(input: $input, media: $media) {
product {
id
media(first: 10) {
nodes {
alt
mediaContentType
preview {
status
}
}
}
}
userErrors {
field
message
}
}
}`,
"variables": {
"input": {
"id": "gid://shopify/Product/912855135"
},
"media": [
{
"originalSource": "https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png",
"alt": "Gray helmet for bikers",
"mediaContentType": "IMAGE"
},
{
"originalSource": "https://www.youtube.com/watch?v=4L8VbGRibj8&list=PLlMkWQ65HlcEoPyG9QayqEaAu0ftj0MMz",
"alt": "Testing helmet resistance against impacts",
"mediaContentType": "EXTERNAL_VIDEO"
}
]
},
},
});
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 UpdateProductWithNewMedia($input: ProductInput!, $media: [CreateMediaInput!]) {
productUpdate(input: $input, media: $media) {
product {
id
media(first: 10) {
nodes {
alt
mediaContentType
preview {
status
}
}
}
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"input": {
"id": "gid://shopify/Product/912855135"
},
"media": [{"originalSource"=>"https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png", "alt"=>"Gray helmet for bikers", "mediaContentType"=>"IMAGE"}, {"originalSource"=>"https://www.youtube.com/watch?v=4L8VbGRibj8&list=PLlMkWQ65HlcEoPyG9QayqEaAu0ftj0MMz", "alt"=>"Testing helmet resistance against impacts", "mediaContentType"=>"EXTERNAL_VIDEO"}]
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "input": {3 "id": "gid://shopify/Product/912855135"4 },5 "media": [6 {7 "originalSource": "https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png",8 "alt": "Gray helmet for bikers",9 "mediaContentType": "IMAGE"10 },11 {12 "originalSource": "https://www.youtube.com/watch?v=4L8VbGRibj8&list=PLlMkWQ65HlcEoPyG9QayqEaAu0ftj0MMz",13 "alt": "Testing helmet resistance against impacts",14 "mediaContentType": "EXTERNAL_VIDEO"15 }16 ]17}
Response
JSON1{2 "productUpdate": {3 "product": {4 "id": "gid://shopify/Product/912855135",5 "media": {6 "nodes": [7 {8 "alt": "Gray helmet for bikers",9 "mediaContentType": "IMAGE",10 "preview": {11 "status": "UPLOADED"12 }13 },14 {15 "alt": "Testing helmet resistance against impacts",16 "mediaContentType": "EXTERNAL_VIDEO",17 "preview": {18 "status": "UPLOADED"19 }20 }21 ]22 }23 },24 "userErrors": []25 }26}