# productUpdate - admin-graphql - MUTATION Version: 2024-10 ## Description 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](https://shopify.dev/api/admin-graphql/latest/mutations/productvariantsbulkupdate). If you want to update a single variant, then use [productVariantUpdate](https://shopify.dev/api/admin-graphql/latest/mutations/productvariantupdate). ### Access Scopes `write_products` access scope. Also: The user must have a permission to update products. ## Arguments * [input](/docs/api/admin-graphql/2024-10/input-objects/ProductInput): ProductInput - The updated properties for a product. * [media](/docs/api/admin-graphql/2024-10/input-objects/CreateMediaInput): CreateMediaInput - List of new media to be added to the product. * [product](/docs/api/admin-graphql/2024-10/input-objects/ProductUpdateInput): ProductUpdateInput - The updated properties for a product. ## Returns * [product](/docs/api/admin-graphql/2024-10/objects/Product): Product The updated product object. * [userErrors](/docs/api/admin-graphql/2024-10/objects/UserError): UserError! The list of errors that occurred from executing the mutation. ## Examples ### Add new media to an existing product Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"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 } } }\",\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/Product/912855135\"\n },\n \"media\": [\n {\n \"originalSource\": \"https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png\",\n \"alt\": \"Gray helmet for bikers\",\n \"mediaContentType\": \"IMAGE\"\n },\n {\n \"originalSource\": \"https://www.youtube.com/watch?v=4L8VbGRibj8&list=PLlMkWQ65HlcEoPyG9QayqEaAu0ftj0MMz\",\n \"alt\": \"Testing helmet resistance against impacts\",\n \"mediaContentType\": \"EXTERNAL_VIDEO\"\n }\n ]\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation UpdateProductWithNewMedia($input: ProductInput!, $media: [CreateMediaInput!]) {\n productUpdate(input: $input, media: $media) {\n product {\n id\n media(first: 10) {\n nodes {\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/Product/912855135\"\n },\n \"media\": [\n {\n \"originalSource\": \"https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png\",\n \"alt\": \"Gray helmet for bikers\",\n \"mediaContentType\": \"IMAGE\"\n },\n {\n \"originalSource\": \"https://www.youtube.com/watch?v=4L8VbGRibj8&list=PLlMkWQ65HlcEoPyG9QayqEaAu0ftj0MMz\",\n \"alt\": \"Testing helmet resistance against impacts\",\n \"mediaContentType\": \"EXTERNAL_VIDEO\"\n }\n ]\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation UpdateProductWithNewMedia($input: ProductInput!, $media: [CreateMediaInput!]) {\n productUpdate(input: $input, media: $media) {\n product {\n id\n media(first: 10) {\n nodes {\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"id\": \"gid://shopify/Product/912855135\"\n },\n \"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\"}]\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation UpdateProductWithNewMedia($input: ProductInput!, $media: [CreateMediaInput!]) {\n productUpdate(input: $input, media: $media) {\n product {\n id\n media(first: 10) {\n nodes {\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"id\": \"gid://shopify/Product/912855135\"\n },\n \"media\": [\n {\n \"originalSource\": \"https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png\",\n \"alt\": \"Gray helmet for bikers\",\n \"mediaContentType\": \"IMAGE\"\n },\n {\n \"originalSource\": \"https://www.youtube.com/watch?v=4L8VbGRibj8&list=PLlMkWQ65HlcEoPyG9QayqEaAu0ftj0MMz\",\n \"alt\": \"Testing helmet resistance against impacts\",\n \"mediaContentType\": \"EXTERNAL_VIDEO\"\n }\n ]\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation UpdateProductWithNewMedia($input: ProductInput!, $media: [CreateMediaInput!]) {\n productUpdate(input: $input, media: $media) {\n product {\n id\n media(first: 10) {\n nodes {\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}" #### Graphql Input { "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" } ] } #### Graphql Response { "data": { "productUpdate": { "product": { "id": "gid://shopify/Product/912855135", "media": { "nodes": [ { "alt": "Gray helmet for bikers", "mediaContentType": "IMAGE", "preview": { "status": "UPLOADED" } }, { "alt": "Testing helmet resistance against impacts", "mediaContentType": "EXTERNAL_VIDEO", "preview": { "status": "UPLOADED" } } ] } }, "userErrors": [] } } } ### Create a new metafield and update another on an existing product Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation updateProductMetafields($input: ProductInput!) { productUpdate(input: $input) { product { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }\",\n \"variables\": {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"liner_material\",\n \"type\": \"single_line_text_field\",\n \"value\": \"Synthetic Leather\"\n },\n {\n \"id\": \"gid://shopify/Metafield/1069229063\",\n \"value\": \"Rubber\"\n }\n ],\n \"id\": \"gid://shopify/Product/108828309\"\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation updateProductMetafields($input: ProductInput!) {\n productUpdate(input: $input) {\n product {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"liner_material\",\n \"type\": \"single_line_text_field\",\n \"value\": \"Synthetic Leather\"\n },\n {\n \"id\": \"gid://shopify/Metafield/1069229063\",\n \"value\": \"Rubber\"\n }\n ],\n \"id\": \"gid://shopify/Product/108828309\"\n }\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation updateProductMetafields($input: ProductInput!) {\n productUpdate(input: $input) {\n product {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"metafields\": [{\"namespace\"=>\"my_field\", \"key\"=>\"liner_material\", \"type\"=>\"single_line_text_field\", \"value\"=>\"Synthetic Leather\"}, {\"id\"=>\"gid://shopify/Metafield/1069229063\", \"value\"=>\"Rubber\"}],\n \"id\": \"gid://shopify/Product/108828309\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation updateProductMetafields($input: ProductInput!) {\n productUpdate(input: $input) {\n product {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"liner_material\",\n \"type\": \"single_line_text_field\",\n \"value\": \"Synthetic Leather\"\n },\n {\n \"id\": \"gid://shopify/Metafield/1069229063\",\n \"value\": \"Rubber\"\n }\n ],\n \"id\": \"gid://shopify/Product/108828309\"\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation updateProductMetafields($input: ProductInput!) {\n productUpdate(input: $input) {\n product {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n}" #### Graphql Input { "input": { "metafields": [ { "namespace": "my_field", "key": "liner_material", "type": "single_line_text_field", "value": "Synthetic Leather" }, { "id": "gid://shopify/Metafield/1069229063", "value": "Rubber" } ], "id": "gid://shopify/Product/108828309" } } #### Graphql Response { "data": { "productUpdate": { "product": { "id": "gid://shopify/Product/108828309", "metafields": { "edges": [ { "node": { "id": "gid://shopify/Metafield/1069229063", "namespace": "my_fields", "key": "sole_material", "value": "Rubber" } }, { "node": { "id": "gid://shopify/Metafield/1069229064", "namespace": "my_field", "key": "liner_material", "value": "Synthetic Leather" } } ] } }, "userErrors": [] } } } ### Update a product's title and return the product ID Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation { productUpdate(input: {id: \\\"gid://shopify/Product/108828309\\\", title: \\\"Sweet new product - GraphQL Edition\\\"}) { product { id } } }\"\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: `mutation {\n productUpdate(input: {id: \"gid://shopify/Product/108828309\", title: \"Sweet new product - GraphQL Edition\"}) {\n product {\n id\n }\n }\n }`,\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation {\n productUpdate(input: {id: \"gid://shopify/Product/108828309\", title: \"Sweet new product - GraphQL Edition\"}) {\n product {\n id\n }\n }\n }\nQUERY\n\nresponse = client.query(query: query)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation {\n productUpdate(input: {id: \"gid://shopify/Product/108828309\", title: \"Sweet new product - GraphQL Edition\"}) {\n product {\n id\n }\n }\n }`,\n);\n\nconst data = await response.json();\n" Graphql query: "mutation {\n productUpdate(input: {id: \"gid://shopify/Product/108828309\", title: \"Sweet new product - GraphQL Edition\"}) {\n product {\n id\n }\n }\n}" #### Graphql Input null #### Graphql Response { "data": { "productUpdate": { "product": { "id": "gid://shopify/Product/108828309" } } } } ### Updates a product Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation ProductUpdate($input: ProductInput!) { productUpdate(input: $input) { product { id title } userErrors { field message } } }\",\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/Product/108828309\",\n \"title\": \"Updated Product Title\"\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation ProductUpdate($input: ProductInput!) {\n productUpdate(input: $input) {\n product {\n id\n title\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"id\": \"gid://shopify/Product/108828309\",\n \"title\": \"Updated Product Title\"\n }\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation ProductUpdate($input: ProductInput!) {\n productUpdate(input: $input) {\n product {\n id\n title\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"id\": \"gid://shopify/Product/108828309\",\n \"title\": \"Updated Product Title\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation ProductUpdate($input: ProductInput!) {\n productUpdate(input: $input) {\n product {\n id\n title\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"id\": \"gid://shopify/Product/108828309\",\n \"title\": \"Updated Product Title\"\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation ProductUpdate($input: ProductInput!) {\n productUpdate(input: $input) {\n product {\n id\n title\n }\n userErrors {\n field\n message\n }\n }\n}" #### Graphql Input { "input": { "id": "gid://shopify/Product/108828309", "title": "Updated Product Title" } } #### Graphql Response { "data": { "productUpdate": { "product": { "id": "gid://shopify/Product/108828309", "title": "Updated Product Title" }, "userErrors": [] } } }