Version: 2024-04
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) { productVariantsBulkUpdate(productId: $productId, variants: $variants) { product { id } productVariants { id metafields(first: 2) { edges { node { namespace key value } } } } userErrors { field message } } }\",\n \"variables\": {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/1070325053\",\n \"metafields\": [\n {\n \"id\": \"gid://shopify/Metafield/1069228989\",\n \"value\": \"SYNTHETIC LEATHER\"\n },\n {\n \"namespace\": \"my_fields\",\n \"key\": \"sole_material\",\n \"value\": \"RUBBER\",\n \"type\": \"single_line_text_field\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325054\",\n \"metafields\": [\n {\n \"id\": \"gid://shopify/Metafield/1069228990\",\n \"value\": \"SYNTHETIC LEATHER\"\n },\n {\n \"namespace\": \"my_fields\",\n \"key\": \"sole_material\",\n \"value\": \"CREPE\",\n \"type\": \"single_line_text_field\"\n }\n ]\n }\n ]\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n product {\n id\n }\n productVariants {\n id\n metafields(first: 2) {\n edges {\n node {\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/1070325053\",\n \"metafields\": [\n {\n \"id\": \"gid://shopify/Metafield/1069228989\",\n \"value\": \"SYNTHETIC LEATHER\"\n },\n {\n \"namespace\": \"my_fields\",\n \"key\": \"sole_material\",\n \"value\": \"RUBBER\",\n \"type\": \"single_line_text_field\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325054\",\n \"metafields\": [\n {\n \"id\": \"gid://shopify/Metafield/1069228990\",\n \"value\": \"SYNTHETIC LEATHER\"\n },\n {\n \"namespace\": \"my_fields\",\n \"key\": \"sole_material\",\n \"value\": \"CREPE\",\n \"type\": \"single_line_text_field\"\n }\n ]\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 productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n product {\n id\n }\n productVariants {\n id\n metafields(first: 2) {\n edges {\n node {\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [{\"id\"=>\"gid://shopify/ProductVariant/1070325053\", \"metafields\"=>[{\"id\"=>\"gid://shopify/Metafield/1069228989\", \"value\"=>\"SYNTHETIC LEATHER\"}, {\"namespace\"=>\"my_fields\", \"key\"=>\"sole_material\", \"value\"=>\"RUBBER\", \"type\"=>\"single_line_text_field\"}]}, {\"id\"=>\"gid://shopify/ProductVariant/1070325054\", \"metafields\"=>[{\"id\"=>\"gid://shopify/Metafield/1069228990\", \"value\"=>\"SYNTHETIC LEATHER\"}, {\"namespace\"=>\"my_fields\", \"key\"=>\"sole_material\", \"value\"=>\"CREPE\", \"type\"=>\"single_line_text_field\"}]}]\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<\"gid://shopify/Product/20995642\",\n \"variants\" => [{\"id\"=>\"gid://shopify/ProductVariant/1070325053\", \"metafields\"=>[{\"id\"=>\"gid://shopify/Metafield/1069228989\", \"value\"=>\"SYNTHETIC LEATHER\"}, {\"namespace\"=>\"my_fields\", \"key\"=>\"sole_material\", \"value\"=>\"RUBBER\", \"type\"=>\"single_line_text_field\"}]}, {\"id\"=>\"gid://shopify/ProductVariant/1070325054\", \"metafields\"=>[{\"id\"=>\"gid://shopify/Metafield/1069228990\", \"value\"=>\"SYNTHETIC LEATHER\"}, {\"namespace\"=>\"my_fields\", \"key\"=>\"sole_material\", \"value\"=>\"CREPE\", \"type\"=>\"single_line_text_field\"}]}],\n];\n\n$response = $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 productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n product {\n id\n }\n productVariants {\n id\n metafields(first: 2) {\n edges {\n node {\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/1070325053\",\n \"metafields\": [\n {\n \"id\": \"gid://shopify/Metafield/1069228989\",\n \"value\": \"SYNTHETIC LEATHER\"\n },\n {\n \"namespace\": \"my_fields\",\n \"key\": \"sole_material\",\n \"value\": \"RUBBER\",\n \"type\": \"single_line_text_field\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325054\",\n \"metafields\": [\n {\n \"id\": \"gid://shopify/Metafield/1069228990\",\n \"value\": \"SYNTHETIC LEATHER\"\n },\n {\n \"namespace\": \"my_fields\",\n \"key\": \"sole_material\",\n \"value\": \"CREPE\",\n \"type\": \"single_line_text_field\"\n }\n ]\n }\n ]\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n product {\n id\n }\n productVariants {\n id\n metafields(first: 2) {\n edges {\n node {\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "productId": "gid://shopify/Product/20995642", "variants": [ { "id": "gid://shopify/ProductVariant/1070325053", "metafields": [ { "id": "gid://shopify/Metafield/1069228989", "value": "SYNTHETIC LEATHER" }, { "namespace": "my_fields", "key": "sole_material", "value": "RUBBER", "type": "single_line_text_field" } ] }, { "id": "gid://shopify/ProductVariant/1070325054", "metafields": [ { "id": "gid://shopify/Metafield/1069228990", "value": "SYNTHETIC LEATHER" }, { "namespace": "my_fields", "key": "sole_material", "value": "CREPE", "type": "single_line_text_field" } ] } ] }
response: { "data": { "productVariantsBulkUpdate": { "product": { "id": "gid://shopify/Product/20995642" }, "productVariants": [ { "id": "gid://shopify/ProductVariant/1070325053", "metafields": { "edges": [ { "node": { "namespace": "my_fields", "key": "liner_material", "value": "SYNTHETIC LEATHER" } }, { "node": { "namespace": "my_fields", "key": "sole_material", "value": "RUBBER" } } ] } }, { "id": "gid://shopify/ProductVariant/1070325054", "metafields": { "edges": [ { "node": { "namespace": "my_fields", "key": "liner_material", "value": "SYNTHETIC LEATHER" } }, { "node": { "namespace": "my_fields", "key": "sole_material", "value": "CREPE" } } ] } } ], "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation UpdateProductVariantsInBulkWithExistingMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!) { productVariantsBulkUpdate(productId: $productId, variants: $variants) { product { id } productVariants { id title media(first: 10) { nodes { id alt mediaContentType preview { status } } } } userErrors { field message } } }\",\n \"variables\": {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/30322695\",\n \"mediaId\": \"gid://shopify/MediaImage/730211239\",\n \"sku\": \"AAA\"\n },\n {\n \"id\": \"gid://shopify/ProductVariant/113711323\",\n \"sku\": \"BBB\"\n }\n ]\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation UpdateProductVariantsInBulkWithExistingMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n product {\n id\n }\n productVariants {\n id\n title\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/30322695\",\n \"mediaId\": \"gid://shopify/MediaImage/730211239\",\n \"sku\": \"AAA\"\n },\n {\n \"id\": \"gid://shopify/ProductVariant/113711323\",\n \"sku\": \"BBB\"\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 UpdateProductVariantsInBulkWithExistingMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n product {\n id\n }\n productVariants {\n id\n title\n media(first: 10) {\n nodes {\n id\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 \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [{\"id\"=>\"gid://shopify/ProductVariant/30322695\", \"mediaId\"=>\"gid://shopify/MediaImage/730211239\", \"sku\"=>\"AAA\"}, {\"id\"=>\"gid://shopify/ProductVariant/113711323\", \"sku\"=>\"BBB\"}]\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<\"gid://shopify/Product/20995642\",\n \"variants\" => [{\"id\"=>\"gid://shopify/ProductVariant/30322695\", \"mediaId\"=>\"gid://shopify/MediaImage/730211239\", \"sku\"=>\"AAA\"}, {\"id\"=>\"gid://shopify/ProductVariant/113711323\", \"sku\"=>\"BBB\"}],\n];\n\n$response = $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 UpdateProductVariantsInBulkWithExistingMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n product {\n id\n }\n productVariants {\n id\n title\n media(first: 10) {\n nodes {\n id\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 \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/30322695\",\n \"mediaId\": \"gid://shopify/MediaImage/730211239\",\n \"sku\": \"AAA\"\n },\n {\n \"id\": \"gid://shopify/ProductVariant/113711323\",\n \"sku\": \"BBB\"\n }\n ]\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation UpdateProductVariantsInBulkWithExistingMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n product {\n id\n }\n productVariants {\n id\n title\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "productId": "gid://shopify/Product/20995642", "variants": [ { "id": "gid://shopify/ProductVariant/30322695", "mediaId": "gid://shopify/MediaImage/730211239", "sku": "AAA" }, { "id": "gid://shopify/ProductVariant/113711323", "sku": "BBB" } ] }
response: { "data": { "productVariantsBulkUpdate": { "product": { "id": "gid://shopify/Product/20995642" }, "productVariants": [ { "id": "gid://shopify/ProductVariant/30322695", "title": "151cm", "media": { "nodes": [ { "id": "gid://shopify/MediaImage/730211239", "alt": "a snowboard", "mediaContentType": "IMAGE", "preview": { "status": "READY" } } ] } }, { "id": "gid://shopify/ProductVariant/113711323", "title": "155cm", "media": { "nodes": [] } } ], "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation UpdateProductVariantsInBulkAndMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!, $media: [CreateMediaInput!]) { productVariantsBulkUpdate(productId: $productId, variants: $variants, media: $media) { product { id media(first: 10) { nodes { id alt mediaContentType preview { status } } } } productVariants { id sku media(first: 10) { nodes { id alt mediaContentType preview { status } } } } userErrors { field message } } }\",\n \"variables\": {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/30322695\",\n \"sku\": \"AAA\"\n },\n {\n \"id\": \"gid://shopify/ProductVariant/113711323\",\n \"sku\": \"BBB\"\n },\n {\n \"id\": \"gid://shopify/ProductVariant/236948360\",\n \"sku\": \"CCC\"\n }\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 UpdateProductVariantsInBulkAndMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!, $media: [CreateMediaInput!]) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants, media: $media) {\n product {\n id\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n productVariants {\n id\n sku\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/30322695\",\n \"sku\": \"AAA\"\n },\n {\n \"id\": \"gid://shopify/ProductVariant/113711323\",\n \"sku\": \"BBB\"\n },\n {\n \"id\": \"gid://shopify/ProductVariant/236948360\",\n \"sku\": \"CCC\"\n }\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 UpdateProductVariantsInBulkAndMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!, $media: [CreateMediaInput!]) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants, media: $media) {\n product {\n id\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n productVariants {\n id\n sku\n media(first: 10) {\n nodes {\n id\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 \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [{\"id\"=>\"gid://shopify/ProductVariant/30322695\", \"sku\"=>\"AAA\"}, {\"id\"=>\"gid://shopify/ProductVariant/113711323\", \"sku\"=>\"BBB\"}, {\"id\"=>\"gid://shopify/ProductVariant/236948360\", \"sku\"=>\"CCC\"}],\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" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<\"gid://shopify/Product/20995642\",\n \"variants\" => [{\"id\"=>\"gid://shopify/ProductVariant/30322695\", \"sku\"=>\"AAA\"}, {\"id\"=>\"gid://shopify/ProductVariant/113711323\", \"sku\"=>\"BBB\"}, {\"id\"=>\"gid://shopify/ProductVariant/236948360\", \"sku\"=>\"CCC\"}],\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\n$response = $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 UpdateProductVariantsInBulkAndMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!, $media: [CreateMediaInput!]) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants, media: $media) {\n product {\n id\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n productVariants {\n id\n sku\n media(first: 10) {\n nodes {\n id\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 \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/30322695\",\n \"sku\": \"AAA\"\n },\n {\n \"id\": \"gid://shopify/ProductVariant/113711323\",\n \"sku\": \"BBB\"\n },\n {\n \"id\": \"gid://shopify/ProductVariant/236948360\",\n \"sku\": \"CCC\"\n }\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 UpdateProductVariantsInBulkAndMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!, $media: [CreateMediaInput!]) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants, media: $media) {\n product {\n id\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n productVariants {\n id\n sku\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "productId": "gid://shopify/Product/20995642", "variants": [ { "id": "gid://shopify/ProductVariant/30322695", "sku": "AAA" }, { "id": "gid://shopify/ProductVariant/113711323", "sku": "BBB" }, { "id": "gid://shopify/ProductVariant/236948360", "sku": "CCC" } ], "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: { "data": { "productVariantsBulkUpdate": { "product": { "id": "gid://shopify/Product/20995642", "media": { "nodes": [ { "id": "gid://shopify/MediaImage/1072273191", "alt": "Gray helmet for bikers", "mediaContentType": "IMAGE", "preview": { "status": "UPLOADED" } }, { "id": "gid://shopify/ExternalVideo/1072273192", "alt": "Testing helmet resistance against impacts", "mediaContentType": "EXTERNAL_VIDEO", "preview": { "status": "UPLOADED" } } ] } }, "productVariants": [ { "id": "gid://shopify/ProductVariant/30322695", "sku": "AAA", "media": { "nodes": [] } }, { "id": "gid://shopify/ProductVariant/113711323", "sku": "BBB", "media": { "nodes": [] } }, { "id": "gid://shopify/ProductVariant/236948360", "sku": "CCC", "media": { "nodes": [] } } ], "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation UpdateProductVariantsOptionValuesInBulk($productId: ID!, $variants: [ProductVariantsBulkInput!]!) { productVariantsBulkUpdate(productId: $productId, variants: $variants) { product { id title options { id position name values optionValues { id name hasVariants } } } productVariants { id title selectedOptions { name value } } userErrors { field message } } }\",\n \"variables\": {\n \"productId\": \"gid://shopify/Product/1072481051\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/1070325050\",\n \"optionValues\": [\n {\n \"name\": \"Green\",\n \"optionName\": \"Color\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325051\",\n \"optionValues\": [\n {\n \"name\": \"Large\",\n \"optionId\": \"gid://shopify/ProductOption/1064576503\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672209\",\n \"optionId\": \"gid://shopify/ProductOption/1064576504\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325052\",\n \"optionValues\": [\n {\n \"name\": \"Medium\",\n \"optionName\": \"Size\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672209\",\n \"optionName\": \"Color\"\n }\n ]\n }\n ]\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation UpdateProductVariantsOptionValuesInBulk($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n product {\n id\n title\n options {\n id\n position\n name\n values\n optionValues {\n id\n name\n hasVariants\n }\n }\n }\n productVariants {\n id\n title\n selectedOptions {\n name\n value\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"productId\": \"gid://shopify/Product/1072481051\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/1070325050\",\n \"optionValues\": [\n {\n \"name\": \"Green\",\n \"optionName\": \"Color\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325051\",\n \"optionValues\": [\n {\n \"name\": \"Large\",\n \"optionId\": \"gid://shopify/ProductOption/1064576503\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672209\",\n \"optionId\": \"gid://shopify/ProductOption/1064576504\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325052\",\n \"optionValues\": [\n {\n \"name\": \"Medium\",\n \"optionName\": \"Size\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672209\",\n \"optionName\": \"Color\"\n }\n ]\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 UpdateProductVariantsOptionValuesInBulk($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n product {\n id\n title\n options {\n id\n position\n name\n values\n optionValues {\n id\n name\n hasVariants\n }\n }\n }\n productVariants {\n id\n title\n selectedOptions {\n name\n value\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"productId\": \"gid://shopify/Product/1072481051\",\n \"variants\": [{\"id\"=>\"gid://shopify/ProductVariant/1070325050\", \"optionValues\"=>[{\"name\"=>\"Green\", \"optionName\"=>\"Color\"}]}, {\"id\"=>\"gid://shopify/ProductVariant/1070325051\", \"optionValues\"=>[{\"name\"=>\"Large\", \"optionId\"=>\"gid://shopify/ProductOption/1064576503\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672209\", \"optionId\"=>\"gid://shopify/ProductOption/1064576504\"}]}, {\"id\"=>\"gid://shopify/ProductVariant/1070325052\", \"optionValues\"=>[{\"name\"=>\"Medium\", \"optionName\"=>\"Size\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672209\", \"optionName\"=>\"Color\"}]}]\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<\"gid://shopify/Product/1072481051\",\n \"variants\" => [{\"id\"=>\"gid://shopify/ProductVariant/1070325050\", \"optionValues\"=>[{\"name\"=>\"Green\", \"optionName\"=>\"Color\"}]}, {\"id\"=>\"gid://shopify/ProductVariant/1070325051\", \"optionValues\"=>[{\"name\"=>\"Large\", \"optionId\"=>\"gid://shopify/ProductOption/1064576503\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672209\", \"optionId\"=>\"gid://shopify/ProductOption/1064576504\"}]}, {\"id\"=>\"gid://shopify/ProductVariant/1070325052\", \"optionValues\"=>[{\"name\"=>\"Medium\", \"optionName\"=>\"Size\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672209\", \"optionName\"=>\"Color\"}]}],\n];\n\n$response = $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 UpdateProductVariantsOptionValuesInBulk($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n product {\n id\n title\n options {\n id\n position\n name\n values\n optionValues {\n id\n name\n hasVariants\n }\n }\n }\n productVariants {\n id\n title\n selectedOptions {\n name\n value\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"productId\": \"gid://shopify/Product/1072481051\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/1070325050\",\n \"optionValues\": [\n {\n \"name\": \"Green\",\n \"optionName\": \"Color\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325051\",\n \"optionValues\": [\n {\n \"name\": \"Large\",\n \"optionId\": \"gid://shopify/ProductOption/1064576503\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672209\",\n \"optionId\": \"gid://shopify/ProductOption/1064576504\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325052\",\n \"optionValues\": [\n {\n \"name\": \"Medium\",\n \"optionName\": \"Size\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672209\",\n \"optionName\": \"Color\"\n }\n ]\n }\n ]\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation UpdateProductVariantsOptionValuesInBulk($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n product {\n id\n title\n options {\n id\n position\n name\n values\n optionValues {\n id\n name\n hasVariants\n }\n }\n }\n productVariants {\n id\n title\n selectedOptions {\n name\n value\n }\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "productId": "gid://shopify/Product/1072481051", "variants": [ { "id": "gid://shopify/ProductVariant/1070325050", "optionValues": [ { "name": "Green", "optionName": "Color" } ] }, { "id": "gid://shopify/ProductVariant/1070325051", "optionValues": [ { "name": "Large", "optionId": "gid://shopify/ProductOption/1064576503" }, { "id": "gid://shopify/ProductOptionValue/1054672209", "optionId": "gid://shopify/ProductOption/1064576504" } ] }, { "id": "gid://shopify/ProductVariant/1070325052", "optionValues": [ { "name": "Medium", "optionName": "Size" }, { "id": "gid://shopify/ProductOptionValue/1054672209", "optionName": "Color" } ] } ] }
response: { "data": { "productVariantsBulkUpdate": { "product": { "id": "gid://shopify/Product/1072481051", "title": "A shirt", "options": [ { "id": "gid://shopify/ProductOption/1064576503", "position": 1, "name": "Size", "values": [ "Small", "Large", "Medium" ], "optionValues": [ { "id": "gid://shopify/ProductOptionValue/1054672206", "name": "Small", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054672208", "name": "Large", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054672207", "name": "Medium", "hasVariants": true } ] }, { "id": "gid://shopify/ProductOption/1064576504", "position": 2, "name": "Color", "values": [ "Green", "Red" ], "optionValues": [ { "id": "gid://shopify/ProductOptionValue/1054672211", "name": "Green", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054672209", "name": "Red", "hasVariants": true } ] } ] }, "productVariants": [ { "id": "gid://shopify/ProductVariant/1070325050", "title": "Small / Green", "selectedOptions": [ { "name": "Size", "value": "Small" }, { "name": "Color", "value": "Green" } ] }, { "id": "gid://shopify/ProductVariant/1070325051", "title": "Large / Red", "selectedOptions": [ { "name": "Size", "value": "Large" }, { "name": "Color", "value": "Red" } ] }, { "id": "gid://shopify/ProductVariant/1070325052", "title": "Medium / Red", "selectedOptions": [ { "name": "Size", "value": "Medium" }, { "name": "Color", "value": "Red" } ] } ], "userErrors": [] } } }