# productUpdateMedia - admin-graphql - MUTATION Version: 2024-07 ## Description Updates media for a product. ### Access Scopes `write_products` access scope. Also: The user must have a permission to update media for a product. ## Arguments * [media](/docs/api/admin-graphql/2024-07/input-objects/UpdateMediaInput): UpdateMediaInput! - A list of media updates. * [productId](/docs/api/admin-graphql/2024-07/scalars/ID): ID! - Specifies the product on which media will be updated. ## Returns * [media](/docs/api/admin-graphql/2024-07/interfaces/Media): Media The updated media object. * [mediaUserErrors](/docs/api/admin-graphql/2024-07/objects/MediaUserError): MediaUserError! The list of errors that occurred from executing the mutation. * [product](/docs/api/admin-graphql/2024-07/objects/Product): Product The product on which media was updated. * [userErrors](/docs/api/admin-graphql/2024-07/objects/UserError): UserError! The list of errors that occurred from executing the mutation. ## Examples ### Modify an existing Product Image Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation ProductImageUpdate($id: ID!) { productUpdateMedia(productId: $id, media: [{id: \\\"gid://shopify/MediaImage/853695510\\\", alt: \\\"Updated alt text.\\\"}]) { media { id alt status ... on MediaImage { image { url } } } mediaUserErrors { field message } } }\",\n \"variables\": {\n \"id\": \"gid://shopify/Product/108828309\"\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation ProductImageUpdate($id: ID!) {\n productUpdateMedia(productId: $id, media: [{id: \"gid://shopify/MediaImage/853695510\", alt: \"Updated alt text.\"}]) {\n media {\n id\n alt\n status\n ... on MediaImage {\n image {\n url\n }\n }\n }\n mediaUserErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"id\": \"gid://shopify/Product/108828309\"\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 ProductImageUpdate($id: ID!) {\n productUpdateMedia(productId: $id, media: [{id: \"gid://shopify/MediaImage/853695510\", alt: \"Updated alt text.\"}]) {\n media {\n id\n alt\n status\n ... on MediaImage {\n image {\n url\n }\n }\n }\n mediaUserErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"id\": \"gid://shopify/Product/108828309\"\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 ProductImageUpdate($id: ID!) {\n productUpdateMedia(productId: $id, media: [{id: \"gid://shopify/MediaImage/853695510\", alt: \"Updated alt text.\"}]) {\n media {\n id\n alt\n status\n ... on MediaImage {\n image {\n url\n }\n }\n }\n mediaUserErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"id\": \"gid://shopify/Product/108828309\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation ProductImageUpdate($id: ID!) {\n productUpdateMedia(productId: $id, media: [{id: \"gid://shopify/MediaImage/853695510\", alt: \"Updated alt text.\"}]) {\n media {\n id\n alt\n status\n ... on MediaImage {\n image {\n url\n }\n }\n }\n mediaUserErrors {\n field\n message\n }\n }\n}" #### Graphql Input { "id": "gid://shopify/Product/108828309" } #### Graphql Response { "data": { "productUpdateMedia": { "media": [ { "id": "gid://shopify/MediaImage/853695510", "alt": "Updated alt text.", "status": "READY", "image": { "url": "https://cdn.shopify.com/s/files/1/2637/1970/products/draft58.jpg?v=1730761095" } } ], "mediaUserErrors": [] } } } ### Update a product's media fields Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) { productUpdateMedia(media: $media, productId: $productId) { media { alt } } }\",\n \"variables\": {\n \"media\": [\n {\n \"alt\": \"Some alt text\",\n \"id\": \"gid://shopify/Video/723685877\"\n },\n {\n \"alt\": \"Some more alt text\",\n \"id\": \"gid://shopify/MediaImage/853695510\"\n }\n ],\n \"productId\": \"gid://shopify/Product/108828309\"\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n media {\n alt\n }\n }\n }`,\n \"variables\": {\n \"media\": [\n {\n \"alt\": \"Some alt text\",\n \"id\": \"gid://shopify/Video/723685877\"\n },\n {\n \"alt\": \"Some more alt text\",\n \"id\": \"gid://shopify/MediaImage/853695510\"\n }\n ],\n \"productId\": \"gid://shopify/Product/108828309\"\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 productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n media {\n alt\n }\n }\n }\nQUERY\n\nvariables = {\n \"media\": [{\"alt\"=>\"Some alt text\", \"id\"=>\"gid://shopify/Video/723685877\"}, {\"alt\"=>\"Some more alt text\", \"id\"=>\"gid://shopify/MediaImage/853695510\"}],\n \"productId\": \"gid://shopify/Product/108828309\"\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 productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n media {\n alt\n }\n }\n }`,\n {\n variables: {\n \"media\": [\n {\n \"alt\": \"Some alt text\",\n \"id\": \"gid://shopify/Video/723685877\"\n },\n {\n \"alt\": \"Some more alt text\",\n \"id\": \"gid://shopify/MediaImage/853695510\"\n }\n ],\n \"productId\": \"gid://shopify/Product/108828309\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n media {\n alt\n }\n }\n}" #### Graphql Input { "media": [ { "alt": "Some alt text", "id": "gid://shopify/Video/723685877" }, { "alt": "Some more alt text", "id": "gid://shopify/MediaImage/853695510" } ], "productId": "gid://shopify/Product/108828309" } #### Graphql Response { "data": { "productUpdateMedia": { "media": [ { "alt": "Some alt text" }, { "alt": "Some more alt text" } ] } } } ### Update new media on a non-existent product Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) { productUpdateMedia(media: $media, productId: $productId) { product { id title } media { alt } mediaUserErrors { field message } } }\",\n \"variables\": {\n \"media\": [\n {\n \"alt\": \"Some alt text\",\n \"id\": \"gid://shopify/Video/723685877\"\n },\n {\n \"alt\": \"Some more alt text\",\n \"id\": \"gid://shopify/MediaImage/853695510\"\n }\n ],\n \"productId\": \"gid://shopify/Product/-1\"\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n product {\n id\n title\n }\n media {\n alt\n }\n mediaUserErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"media\": [\n {\n \"alt\": \"Some alt text\",\n \"id\": \"gid://shopify/Video/723685877\"\n },\n {\n \"alt\": \"Some more alt text\",\n \"id\": \"gid://shopify/MediaImage/853695510\"\n }\n ],\n \"productId\": \"gid://shopify/Product/-1\"\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 productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n product {\n id\n title\n }\n media {\n alt\n }\n mediaUserErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"media\": [{\"alt\"=>\"Some alt text\", \"id\"=>\"gid://shopify/Video/723685877\"}, {\"alt\"=>\"Some more alt text\", \"id\"=>\"gid://shopify/MediaImage/853695510\"}],\n \"productId\": \"gid://shopify/Product/-1\"\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 productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n product {\n id\n title\n }\n media {\n alt\n }\n mediaUserErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"media\": [\n {\n \"alt\": \"Some alt text\",\n \"id\": \"gid://shopify/Video/723685877\"\n },\n {\n \"alt\": \"Some more alt text\",\n \"id\": \"gid://shopify/MediaImage/853695510\"\n }\n ],\n \"productId\": \"gid://shopify/Product/-1\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n product {\n id\n title\n }\n media {\n alt\n }\n mediaUserErrors {\n field\n message\n }\n }\n}" #### Graphql Input { "media": [ { "alt": "Some alt text", "id": "gid://shopify/Video/723685877" }, { "alt": "Some more alt text", "id": "gid://shopify/MediaImage/853695510" } ], "productId": "gid://shopify/Product/-1" } #### Graphql Response { "data": { "productUpdateMedia": { "product": null, "media": null, "mediaUserErrors": [ { "field": [ "productId" ], "message": "Product does not exist" } ] } } } ### Update non-existent media on a non-existent product Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) { productUpdateMedia(media: $media, productId: $productId) { product { id title } media { alt } mediaUserErrors { field message code } } }\",\n \"variables\": {\n \"media\": [\n {\n \"alt\": \"Some more alt text\",\n \"id\": \"gid://shopify/MediaImage/-1\"\n }\n ],\n \"productId\": \"gid://shopify/Product/-1\"\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n product {\n id\n title\n }\n media {\n alt\n }\n mediaUserErrors {\n field\n message\n code\n }\n }\n }`,\n \"variables\": {\n \"media\": [\n {\n \"alt\": \"Some more alt text\",\n \"id\": \"gid://shopify/MediaImage/-1\"\n }\n ],\n \"productId\": \"gid://shopify/Product/-1\"\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 productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n product {\n id\n title\n }\n media {\n alt\n }\n mediaUserErrors {\n field\n message\n code\n }\n }\n }\nQUERY\n\nvariables = {\n \"media\": [{\"alt\"=>\"Some more alt text\", \"id\"=>\"gid://shopify/MediaImage/-1\"}],\n \"productId\": \"gid://shopify/Product/-1\"\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 productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n product {\n id\n title\n }\n media {\n alt\n }\n mediaUserErrors {\n field\n message\n code\n }\n }\n }`,\n {\n variables: {\n \"media\": [\n {\n \"alt\": \"Some more alt text\",\n \"id\": \"gid://shopify/MediaImage/-1\"\n }\n ],\n \"productId\": \"gid://shopify/Product/-1\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n product {\n id\n title\n }\n media {\n alt\n }\n mediaUserErrors {\n field\n message\n code\n }\n }\n}" #### Graphql Input { "media": [ { "alt": "Some more alt text", "id": "gid://shopify/MediaImage/-1" } ], "productId": "gid://shopify/Product/-1" } #### Graphql Response { "data": { "productUpdateMedia": { "product": null, "media": null, "mediaUserErrors": [ { "field": [ "productId" ], "message": "Product does not exist", "code": "PRODUCT_DOES_NOT_EXIST" } ] } } } ### Update non-existent media on a valid product Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) { productUpdateMedia(media: $media, productId: $productId) { product { id title } media { alt } mediaUserErrors { field message code } } }\",\n \"variables\": {\n \"media\": [\n {\n \"alt\": \"Some more alt text\",\n \"id\": \"gid://shopify/MediaImage/-1\"\n }\n ],\n \"productId\": \"gid://shopify/Product/108828309\"\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n product {\n id\n title\n }\n media {\n alt\n }\n mediaUserErrors {\n field\n message\n code\n }\n }\n }`,\n \"variables\": {\n \"media\": [\n {\n \"alt\": \"Some more alt text\",\n \"id\": \"gid://shopify/MediaImage/-1\"\n }\n ],\n \"productId\": \"gid://shopify/Product/108828309\"\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 productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n product {\n id\n title\n }\n media {\n alt\n }\n mediaUserErrors {\n field\n message\n code\n }\n }\n }\nQUERY\n\nvariables = {\n \"media\": [{\"alt\"=>\"Some more alt text\", \"id\"=>\"gid://shopify/MediaImage/-1\"}],\n \"productId\": \"gid://shopify/Product/108828309\"\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 productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n product {\n id\n title\n }\n media {\n alt\n }\n mediaUserErrors {\n field\n message\n code\n }\n }\n }`,\n {\n variables: {\n \"media\": [\n {\n \"alt\": \"Some more alt text\",\n \"id\": \"gid://shopify/MediaImage/-1\"\n }\n ],\n \"productId\": \"gid://shopify/Product/108828309\"\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation productUpdateMedia($media: [UpdateMediaInput!]!, $productId: ID!) {\n productUpdateMedia(media: $media, productId: $productId) {\n product {\n id\n title\n }\n media {\n alt\n }\n mediaUserErrors {\n field\n message\n code\n }\n }\n}" #### Graphql Input { "media": [ { "alt": "Some more alt text", "id": "gid://shopify/MediaImage/-1" } ], "productId": "gid://shopify/Product/108828309" } #### Graphql Response { "data": { "productUpdateMedia": { "product": { "id": "gid://shopify/Product/108828309", "title": "Draft" }, "media": null, "mediaUserErrors": [ { "field": [ "media" ], "message": "Media id gid://shopify/MediaImage/-1 does not exist", "code": "MEDIA_DOES_NOT_EXIST" } ] } } }