# productVariantsBulkUpdate - admin-graphql - MUTATION Version: 2024-07 ## Description Updates multiple variants in a single product. This mutation can be called directly or via the bulkOperation. ### Access Scopes `write_products` access scope. Also: The user must have a permission to update product variants. ## Arguments * [allowPartialUpdates](/docs/api/admin-graphql/2024-07/scalars/Boolean): Boolean - When partial updates are allowed, valid variant changes may be persisted even if some of the variants updated have invalid data and cannot be persisted. When partial updates are not allowed, any error will prevent all variants from updating. * [media](/docs/api/admin-graphql/2024-07/input-objects/CreateMediaInput): CreateMediaInput - List of new media to be added to the product. * [productId](/docs/api/admin-graphql/2024-07/scalars/ID): ID! - The ID of the product associated with the variants to update. * [variants](/docs/api/admin-graphql/2024-07/input-objects/ProductVariantsBulkInput): ProductVariantsBulkInput! - An array of product variants to update. ## Returns * [product](/docs/api/admin-graphql/2024-07/objects/Product): Product The updated product object. * [productVariants](/docs/api/admin-graphql/2024-07/objects/ProductVariant): ProductVariant The updated variants. * [userErrors](/docs/api/admin-graphql/2024-07/objects/ProductVariantsBulkUpdateUserError): ProductVariantsBulkUpdateUserError! The list of errors that occurred from executing the mutation. ## Examples ### Create and update metafields when updating product variants in bulk 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 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/1070325197\",\n \"metafields\": [\n {\n \"id\": \"gid://shopify/Metafield/1069229095\",\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/1070325198\",\n \"metafields\": [\n {\n \"id\": \"gid://shopify/Metafield/1069229096\",\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/1070325197\",\n \"metafields\": [\n {\n \"id\": \"gid://shopify/Metafield/1069229095\",\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/1070325198\",\n \"metafields\": [\n {\n \"id\": \"gid://shopify/Metafield/1069229096\",\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/1070325197\", \"metafields\"=>[{\"id\"=>\"gid://shopify/Metafield/1069229095\", \"value\"=>\"SYNTHETIC LEATHER\"}, {\"namespace\"=>\"my_fields\", \"key\"=>\"sole_material\", \"value\"=>\"RUBBER\", \"type\"=>\"single_line_text_field\"}]}, {\"id\"=>\"gid://shopify/ProductVariant/1070325198\", \"metafields\"=>[{\"id\"=>\"gid://shopify/Metafield/1069229096\", \"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" 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/1070325197\",\n \"metafields\": [\n {\n \"id\": \"gid://shopify/Metafield/1069229095\",\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/1070325198\",\n \"metafields\": [\n {\n \"id\": \"gid://shopify/Metafield/1069229096\",\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}" #### Graphql Input { "productId": "gid://shopify/Product/20995642", "variants": [ { "id": "gid://shopify/ProductVariant/1070325197", "metafields": [ { "id": "gid://shopify/Metafield/1069229095", "value": "SYNTHETIC LEATHER" }, { "namespace": "my_fields", "key": "sole_material", "value": "RUBBER", "type": "single_line_text_field" } ] }, { "id": "gid://shopify/ProductVariant/1070325198", "metafields": [ { "id": "gid://shopify/Metafield/1069229096", "value": "SYNTHETIC LEATHER" }, { "namespace": "my_fields", "key": "sole_material", "value": "CREPE", "type": "single_line_text_field" } ] } ] } #### Graphql Response { "data": { "productVariantsBulkUpdate": { "product": { "id": "gid://shopify/Product/20995642" }, "productVariants": [ { "id": "gid://shopify/ProductVariant/1070325197", "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/1070325198", "metafields": { "edges": [ { "node": { "namespace": "my_fields", "key": "liner_material", "value": "SYNTHETIC LEATHER" } }, { "node": { "namespace": "my_fields", "key": "sole_material", "value": "CREPE" } } ] } } ], "userErrors": [] } } } ### Modify an existing Product Variant 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 ProductVariantsUpdate($productId: ID!) { productVariantsBulkUpdate(productId: $productId, variants: [{id: \\\"gid://shopify/ProductVariant/1\\\", barcode: \\\"12345\\\"}, {id: \\\"gid://shopify/ProductVariant/2\\\", barcode: \\\"67890\\\"}]) { 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/1\",\n \"barcode\": \"12345\"\n },\n {\n \"id\": \"gid://shopify/ProductVariant/2\",\n \"barcode\": \"67890\"\n }\n ]\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation ProductVariantsUpdate($productId: ID!) {\n productVariantsBulkUpdate(productId: $productId, variants: [{id: \"gid://shopify/ProductVariant/1\", barcode: \"12345\"}, {id: \"gid://shopify/ProductVariant/2\", barcode: \"67890\"}]) {\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/1\",\n \"barcode\": \"12345\"\n },\n {\n \"id\": \"gid://shopify/ProductVariant/2\",\n \"barcode\": \"67890\"\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 ProductVariantsUpdate($productId: ID!) {\n productVariantsBulkUpdate(productId: $productId, variants: [{id: \"gid://shopify/ProductVariant/1\", barcode: \"12345\"}, {id: \"gid://shopify/ProductVariant/2\", barcode: \"67890\"}]) {\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/1\", \"barcode\"=>\"12345\"}, {\"id\"=>\"gid://shopify/ProductVariant/2\", \"barcode\"=>\"67890\"}]\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 ProductVariantsUpdate($productId: ID!) {\n productVariantsBulkUpdate(productId: $productId, variants: [{id: \"gid://shopify/ProductVariant/1\", barcode: \"12345\"}, {id: \"gid://shopify/ProductVariant/2\", barcode: \"67890\"}]) {\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/1\",\n \"barcode\": \"12345\"\n },\n {\n \"id\": \"gid://shopify/ProductVariant/2\",\n \"barcode\": \"67890\"\n }\n ]\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation ProductVariantsUpdate($productId: ID!) {\n productVariantsBulkUpdate(productId: $productId, variants: [{id: \"gid://shopify/ProductVariant/1\", barcode: \"12345\"}, {id: \"gid://shopify/ProductVariant/2\", barcode: \"67890\"}]) {\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}" #### Graphql Input { "productId": "gid://shopify/Product/20995642", "variants": [ { "id": "gid://shopify/ProductVariant/1", "barcode": "12345" }, { "id": "gid://shopify/ProductVariant/2", "barcode": "67890" } ] } #### Graphql Response { "data": { "productVariantsBulkUpdate": { "product": { "id": "gid://shopify/Product/20995642" }, "productVariants": null, "userErrors": [ { "field": [ "variants", "0", "id" ], "message": "Product variant does not exist" }, { "field": [ "variants", "1", "id" ], "message": "Product variant does not exist" } ] } } } ### Update product variants with option values 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 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/1072481069\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/1070325199\",\n \"optionValues\": [\n {\n \"name\": \"Green\",\n \"optionName\": \"Color\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325200\",\n \"optionValues\": [\n {\n \"name\": \"Large\",\n \"optionId\": \"gid://shopify/ProductOption/1064576536\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672367\",\n \"optionId\": \"gid://shopify/ProductOption/1064576537\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325201\",\n \"optionValues\": [\n {\n \"name\": \"Medium\",\n \"optionName\": \"Size\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672367\",\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/1072481069\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/1070325199\",\n \"optionValues\": [\n {\n \"name\": \"Green\",\n \"optionName\": \"Color\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325200\",\n \"optionValues\": [\n {\n \"name\": \"Large\",\n \"optionId\": \"gid://shopify/ProductOption/1064576536\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672367\",\n \"optionId\": \"gid://shopify/ProductOption/1064576537\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325201\",\n \"optionValues\": [\n {\n \"name\": \"Medium\",\n \"optionName\": \"Size\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672367\",\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/1072481069\",\n \"variants\": [{\"id\"=>\"gid://shopify/ProductVariant/1070325199\", \"optionValues\"=>[{\"name\"=>\"Green\", \"optionName\"=>\"Color\"}]}, {\"id\"=>\"gid://shopify/ProductVariant/1070325200\", \"optionValues\"=>[{\"name\"=>\"Large\", \"optionId\"=>\"gid://shopify/ProductOption/1064576536\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672367\", \"optionId\"=>\"gid://shopify/ProductOption/1064576537\"}]}, {\"id\"=>\"gid://shopify/ProductVariant/1070325201\", \"optionValues\"=>[{\"name\"=>\"Medium\", \"optionName\"=>\"Size\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672367\", \"optionName\"=>\"Color\"}]}]\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 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/1072481069\",\n \"variants\": [\n {\n \"id\": \"gid://shopify/ProductVariant/1070325199\",\n \"optionValues\": [\n {\n \"name\": \"Green\",\n \"optionName\": \"Color\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325200\",\n \"optionValues\": [\n {\n \"name\": \"Large\",\n \"optionId\": \"gid://shopify/ProductOption/1064576536\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672367\",\n \"optionId\": \"gid://shopify/ProductOption/1064576537\"\n }\n ]\n },\n {\n \"id\": \"gid://shopify/ProductVariant/1070325201\",\n \"optionValues\": [\n {\n \"name\": \"Medium\",\n \"optionName\": \"Size\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672367\",\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}" #### Graphql Input { "productId": "gid://shopify/Product/1072481069", "variants": [ { "id": "gid://shopify/ProductVariant/1070325199", "optionValues": [ { "name": "Green", "optionName": "Color" } ] }, { "id": "gid://shopify/ProductVariant/1070325200", "optionValues": [ { "name": "Large", "optionId": "gid://shopify/ProductOption/1064576536" }, { "id": "gid://shopify/ProductOptionValue/1054672367", "optionId": "gid://shopify/ProductOption/1064576537" } ] }, { "id": "gid://shopify/ProductVariant/1070325201", "optionValues": [ { "name": "Medium", "optionName": "Size" }, { "id": "gid://shopify/ProductOptionValue/1054672367", "optionName": "Color" } ] } ] } #### Graphql Response { "data": { "productVariantsBulkUpdate": { "product": { "id": "gid://shopify/Product/1072481069", "title": "A shirt", "options": [ { "id": "gid://shopify/ProductOption/1064576536", "position": 1, "name": "Size", "values": [ "Small", "Large", "Medium" ], "optionValues": [ { "id": "gid://shopify/ProductOptionValue/1054672364", "name": "Small", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054672366", "name": "Large", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054672365", "name": "Medium", "hasVariants": true } ] }, { "id": "gid://shopify/ProductOption/1064576537", "position": 2, "name": "Color", "values": [ "Green", "Red" ], "optionValues": [ { "id": "gid://shopify/ProductOptionValue/1054672369", "name": "Green", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054672367", "name": "Red", "hasVariants": true } ] } ] }, "productVariants": [ { "id": "gid://shopify/ProductVariant/1070325199", "title": "Small / Green", "selectedOptions": [ { "name": "Size", "value": "Small" }, { "name": "Color", "value": "Green" } ] }, { "id": "gid://shopify/ProductVariant/1070325200", "title": "Large / Red", "selectedOptions": [ { "name": "Size", "value": "Large" }, { "name": "Color", "value": "Red" } ] }, { "id": "gid://shopify/ProductVariant/1070325201", "title": "Medium / Red", "selectedOptions": [ { "name": "Size", "value": "Medium" }, { "name": "Color", "value": "Red" } ] } ], "userErrors": [] } } }