product Variants Bulk Createmutation
Requires write
access scope. Also: The user must have a permission to create product variants.
Creates multiple variants in a single product. This mutation can be called directly or via the bulkOperation.
Arguments
List of new media to be added to the product.
The ID of the product on which to create the variants.
The strategy defines which behavior the mutation should observe, such as whether to keep or delete the standalone variant (when product has only a single or default variant) when creating new variants in bulk.
An array of product variants to be created.
ProductVariantsBulkCreatePayload returns
The updated product object.
The newly created variants.
The list of errors that occurred from executing the mutation.
Code examples for MUTATION: productVariantsBulkCreate
Query Reference for MUTATION: productVariantsBulkCreate
"mutation productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\n product {\n # Product fields\n }\n productVariants {\n # ProductVariant fields\n }\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: productVariantsBulkCreate
"{\n \"media\": [\n {\n \"alt\": \"<your-alt>\",\n \"mediaContentType\": \"EXTERNAL_VIDEO\",\n \"originalSource\": \"<your-originalSource>\"\n }\n ],\n \"productId\": \"gid://shopify/<objectName>/10079785100\",\n \"strategy\": \"DEFAULT\",\n \"variants\": [\n {\n \"barcode\": \"<your-barcode>\",\n \"compareAtPrice\": \"100.57\",\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"inventoryItem\": {\n \"cost\": \"29.99\",\n \"countryCodeOfOrigin\": \"AC\",\n \"countryHarmonizedSystemCodes\": [\n {\n \"countryCode\": \"AC\",\n \"harmonizedSystemCode\": \"<your-harmonizedSystemCode>\"\n }\n ],\n \"harmonizedSystemCode\": \"<your-harmonizedSystemCode>\",\n \"measurement\": {\n \"weight\": {\n \"unit\": \"GRAMS\",\n \"value\": 1.1\n }\n },\n \"provinceCodeOfOrigin\": \"<your-provinceCodeOfOrigin>\",\n \"requiresShipping\": true,\n \"sku\": \"<your-sku>\",\n \"tracked\": true\n },\n \"inventoryPolicy\": \"CONTINUE\",\n \"inventoryQuantities\": [\n {\n \"availableQuantity\": 1,\n \"locationId\": \"gid://shopify/<objectName>/10079785100\"\n }\n ],\n \"mediaId\": \"gid://shopify/<objectName>/10079785100\",\n \"mediaSrc\": [\n \"<your-mediaSrc>\"\n ],\n \"metafields\": [\n {\n \"description\": \"<your-description>\",\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"key\": \"<your-key>\",\n \"namespace\": \"<your-namespace>\",\n \"type\": \"<your-type>\",\n \"value\": \"<your-value>\"\n }\n ],\n \"optionValues\": [\n {\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"linkedMetafieldValue\": \"<your-linkedMetafieldValue>\",\n \"name\": \"<your-name>\",\n \"optionId\": \"gid://shopify/<objectName>/10079785100\",\n \"optionName\": \"<your-optionName>\"\n }\n ],\n \"price\": \"100.57\",\n \"taxCode\": \"<your-taxCode>\",\n \"taxable\": true\n }\n ]\n}"
Schema Reference for MUTATION: productVariantsBulkCreate
"input CreateMediaInput {\n alt: String\n mediaContentType: MediaContentType!\n originalSource: String!\n}\n\ninput ProductVariantsBulkInput {\n barcode: String\n compareAtPrice: Money\n id: ID\n inventoryItem: InventoryItemInput\n inventoryPolicy: ProductVariantInventoryPolicy\n inventoryQuantities: [InventoryLevelInput!]\n mediaId: ID\n mediaSrc: [String!]\n metafields: [MetafieldInput!]\n optionValues: [VariantOptionValueInput!]\n price: Money\n privateMetafields: [PrivateMetafieldInput!]\n taxCode: String\n taxable: Boolean\n}\n\ninput InventoryItemInput {\n cost: Decimal\n countryCodeOfOrigin: CountryCode\n countryHarmonizedSystemCodes: [CountryHarmonizedSystemCodeInput!]\n harmonizedSystemCode: String\n measurement: InventoryItemMeasurementInput\n provinceCodeOfOrigin: String\n requiresShipping: Boolean\n sku: String\n tracked: Boolean\n}\n\ninput InventoryLevelInput {\n availableQuantity: Int!\n locationId: ID!\n}\n\ninput MetafieldInput {\n description: String\n id: ID\n key: String\n namespace: String\n type: String\n value: String\n}\n\ninput VariantOptionValueInput {\n id: ID\n linkedMetafieldValue: String\n name: String\n optionId: ID\n optionName: String\n}\n\ninput PrivateMetafieldInput {\n key: String!\n namespace: String!\n owner: ID\n valueInput: PrivateMetafieldValueInput!\n}\n"
Display Examples for MUTATION: productVariantsBulkCreate
[ { "example": { "type_name": "productvariantsbulkcreate", "title": "Create product variants using existing and new option values", "description": "Creates variants with the option values specified. Both the option and the option value can be specified\nwith either an ID or a name, and these can be freely combined. An option referenced with either the\n`optionId` or `optionName` field must exist on the product. An option value specified with\nthe `id` field must exist on the option. When using the `optionValue` field to specify\nan option value by `name`, an existing value is linked to the new variant\nif an option value with the name exists on the option. Otherwise, a new option value is created.\nAll variants must have one value specified for every existing product option.\n", "query_string": "mutation productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\n userErrors {\n field\n message\n }\n product {\n id\n options {\n id\n name\n values\n position\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 }\n}", "variables": { "productId": "gid://shopify/Product/1072481060", "variants": [ { "optionValues": [ { "name": "Red", "optionName": "Color" }, { "name": "Brand new style", "optionId": "gid://shopify/ProductOption/1064576522" }, { "name": "Silk", "optionName": "Material" } ], "price": 22 }, { "optionValues": [ { "name": "Brand new style", "optionName": "Style" }, { "id": "gid://shopify/ProductOptionValue/1054672262", "optionName": "Color" }, { "name": "Silk", "optionName": "Material" } ], "price": 23.5 }, { "optionValues": [ { "name": "Brand new style", "optionId": "gid://shopify/ProductOption/1064576522" }, { "id": "gid://shopify/ProductOptionValue/1054672263", "optionId": "gid://shopify/ProductOption/1064576521" }, { "id": "gid://shopify/ProductOptionValue/1054672265", "optionId": "gid://shopify/ProductOption/1064576523" } ], "price": 29.5 } ] }, "response": { "data": { "productVariantsBulkCreate": { "userErrors": [], "product": { "id": "gid://shopify/Product/1072481060", "options": [ { "id": "gid://shopify/ProductOption/1064576521", "name": "Color", "values": [ "Blue", "Red" ], "position": 1, "optionValues": [ { "id": "gid://shopify/ProductOptionValue/1054672262", "name": "Blue", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054672263", "name": "Red", "hasVariants": true } ] }, { "id": "gid://shopify/ProductOption/1064576522", "name": "Style", "values": [ "Old style", "Brand new style" ], "position": 2, "optionValues": [ { "id": "gid://shopify/ProductOptionValue/1054672264", "name": "Old style", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054672267", "name": "Brand new style", "hasVariants": true } ] }, { "id": "gid://shopify/ProductOption/1064576523", "name": "Material", "values": [ "Polyester", "Silk" ], "position": 3, "optionValues": [ { "id": "gid://shopify/ProductOptionValue/1054672265", "name": "Polyester", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054672266", "name": "Silk", "hasVariants": true } ] } ] }, "productVariants": [ { "id": "gid://shopify/ProductVariant/1070325093", "title": "Red / Brand new style / Silk", "selectedOptions": [ { "name": "Color", "value": "Red" }, { "name": "Style", "value": "Brand new style" }, { "name": "Material", "value": "Silk" } ] }, { "id": "gid://shopify/ProductVariant/1070325094", "title": "Blue / Brand new style / Silk", "selectedOptions": [ { "name": "Color", "value": "Blue" }, { "name": "Style", "value": "Brand new style" }, { "name": "Material", "value": "Silk" } ] }, { "id": "gid://shopify/ProductVariant/1070325095", "title": "Red / Brand new style / Polyester", "selectedOptions": [ { "name": "Color", "value": "Red" }, { "name": "Style", "value": "Brand new style" }, { "name": "Material", "value": "Polyester" } ] } ] } } }, "api_name": "admin", "minimum_api_version": "2024-04", "maximum_api_version": "unstable", "location": "/components/merchandising/test/unit/merchandising/graph_api/admin/mutations/product_variants_bulk_create_test.rb", "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 productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) { productVariantsBulkCreate(productId: $productId, variants: $variants) { userErrors { field message } product { id options { id name values position optionValues { id name hasVariants } } } productVariants { id title selectedOptions { name value } } } }\",\n \"variables\": {\n \"productId\": \"gid://shopify/Product/1072481060\",\n \"variants\": [\n {\n \"optionValues\": [\n {\n \"name\": \"Red\",\n \"optionName\": \"Color\"\n },\n {\n \"name\": \"Brand new style\",\n \"optionId\": \"gid://shopify/ProductOption/1064576522\"\n },\n {\n \"name\": \"Silk\",\n \"optionName\": \"Material\"\n }\n ],\n \"price\": 22.0\n },\n {\n \"optionValues\": [\n {\n \"name\": \"Brand new style\",\n \"optionName\": \"Style\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672262\",\n \"optionName\": \"Color\"\n },\n {\n \"name\": \"Silk\",\n \"optionName\": \"Material\"\n }\n ],\n \"price\": 23.5\n },\n {\n \"optionValues\": [\n {\n \"name\": \"Brand new style\",\n \"optionId\": \"gid://shopify/ProductOption/1064576522\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672263\",\n \"optionId\": \"gid://shopify/ProductOption/1064576521\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672265\",\n \"optionId\": \"gid://shopify/ProductOption/1064576523\"\n }\n ],\n \"price\": 29.5\n }\n ]\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\n userErrors {\n field\n message\n }\n product {\n id\n options {\n id\n name\n values\n position\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 }\n }`,\n {\n variables: {\n \"productId\": \"gid://shopify/Product/1072481060\",\n \"variants\": [\n {\n \"optionValues\": [\n {\n \"name\": \"Red\",\n \"optionName\": \"Color\"\n },\n {\n \"name\": \"Brand new style\",\n \"optionId\": \"gid://shopify/ProductOption/1064576522\"\n },\n {\n \"name\": \"Silk\",\n \"optionName\": \"Material\"\n }\n ],\n \"price\": 22.0\n },\n {\n \"optionValues\": [\n {\n \"name\": \"Brand new style\",\n \"optionName\": \"Style\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672262\",\n \"optionName\": \"Color\"\n },\n {\n \"name\": \"Silk\",\n \"optionName\": \"Material\"\n }\n ],\n \"price\": 23.5\n },\n {\n \"optionValues\": [\n {\n \"name\": \"Brand new style\",\n \"optionId\": \"gid://shopify/ProductOption/1064576522\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672263\",\n \"optionId\": \"gid://shopify/ProductOption/1064576521\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672265\",\n \"optionId\": \"gid://shopify/ProductOption/1064576523\"\n }\n ],\n \"price\": 29.5\n }\n ]\n },\n },\n);\n\nconst data = await response.json();\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 productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\n userErrors {\n field\n message\n }\n product {\n id\n options {\n id\n name\n values\n position\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 }\n }\nQUERY\n\nvariables = {\n \"productId\": \"gid://shopify/Product/1072481060\",\n \"variants\": [{\"optionValues\"=>[{\"name\"=>\"Red\", \"optionName\"=>\"Color\"}, {\"name\"=>\"Brand new style\", \"optionId\"=>\"gid://shopify/ProductOption/1064576522\"}, {\"name\"=>\"Silk\", \"optionName\"=>\"Material\"}], \"price\"=>22.0}, {\"optionValues\"=>[{\"name\"=>\"Brand new style\", \"optionName\"=>\"Style\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672262\", \"optionName\"=>\"Color\"}, {\"name\"=>\"Silk\", \"optionName\"=>\"Material\"}], \"price\"=>23.5}, {\"optionValues\"=>[{\"name\"=>\"Brand new style\", \"optionId\"=>\"gid://shopify/ProductOption/1064576522\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672263\", \"optionId\"=>\"gid://shopify/ProductOption/1064576521\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672265\", \"optionId\"=>\"gid://shopify/ProductOption/1064576523\"}], \"price\"=>29.5}]\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\n userErrors {\n field\n message\n }\n product {\n id\n options {\n id\n name\n values\n position\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 }\n }`,\n \"variables\": {\n \"productId\": \"gid://shopify/Product/1072481060\",\n \"variants\": [\n {\n \"optionValues\": [\n {\n \"name\": \"Red\",\n \"optionName\": \"Color\"\n },\n {\n \"name\": \"Brand new style\",\n \"optionId\": \"gid://shopify/ProductOption/1064576522\"\n },\n {\n \"name\": \"Silk\",\n \"optionName\": \"Material\"\n }\n ],\n \"price\": 22.0\n },\n {\n \"optionValues\": [\n {\n \"name\": \"Brand new style\",\n \"optionName\": \"Style\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672262\",\n \"optionName\": \"Color\"\n },\n {\n \"name\": \"Silk\",\n \"optionName\": \"Material\"\n }\n ],\n \"price\": 23.5\n },\n {\n \"optionValues\": [\n {\n \"name\": \"Brand new style\",\n \"optionId\": \"gid://shopify/ProductOption/1064576522\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672263\",\n \"optionId\": \"gid://shopify/ProductOption/1064576521\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672265\",\n \"optionId\": \"gid://shopify/ProductOption/1064576523\"\n }\n ],\n \"price\": 29.5\n }\n ]\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\n userErrors {\n field\n message\n }\n product {\n id\n options {\n id\n name\n values\n position\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 }\n }\nQUERY;\n\n$variables = [\n \"productId\" => \"gid://shopify/Product/1072481060\",\n \"variants\" => [{\"optionValues\"=>[{\"name\"=>\"Red\", \"optionName\"=>\"Color\"}, {\"name\"=>\"Brand new style\", \"optionId\"=>\"gid://shopify/ProductOption/1064576522\"}, {\"name\"=>\"Silk\", \"optionName\"=>\"Material\"}], \"price\"=>22.0}, {\"optionValues\"=>[{\"name\"=>\"Brand new style\", \"optionName\"=>\"Style\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672262\", \"optionName\"=>\"Color\"}, {\"name\"=>\"Silk\", \"optionName\"=>\"Material\"}], \"price\"=>23.5}, {\"optionValues\"=>[{\"name\"=>\"Brand new style\", \"optionId\"=>\"gid://shopify/ProductOption/1064576522\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672263\", \"optionId\"=>\"gid://shopify/ProductOption/1064576521\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672265\", \"optionId\"=>\"gid://shopify/ProductOption/1064576523\"}], \"price\"=>29.5}],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "productId", "description": "The ID of the product on which to create the variants.", "type": { "kind": "SCALAR", "name": "ID", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "ID!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "productId", "argValue": " \"gid://shopify/Product/1072481060\"", "typeKind": "MUTATION" }, { "arg": { "name": "variants", "description": "An array of product variants to be created.", "type": { "kind": "INPUT_OBJECT", "name": "ProductVariantsBulkInput", "list": true, "non_null": true }, "defaultValue": null, "typeSignature": "[ProductVariantsBulkInput!]!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "variants", "argValue": " [{\"optionValues\":[{\"name\":\"Red\",\"optionName\":\"Color\"},{\"name\":\"Brand new style\",\"optionId\":\"gid://shopify/ProductOption/1064576522\"},{\"name\":\"Silk\",\"optionName\":\"Material\"}],\"price\":22},{\"optionValues\":[{\"name\":\"Brand new style\",\"optionName\":\"Style\"},{\"id\":\"gid://shopify/ProductOptionValue/1054672262\",\"optionName\":\"Color\"},{\"name\":\"Silk\",\"optionName\":\"Material\"}],\"price\":23.5},{\"optionValues\":[{\"name\":\"Brand new style\",\"optionId\":\"gid://shopify/ProductOption/1064576522\"},{\"id\":\"gid://shopify/ProductOptionValue/1054672263\",\"optionId\":\"gid://shopify/ProductOption/1064576521\"},{\"id\":\"gid://shopify/ProductOptionValue/1054672265\",\"optionId\":\"gid://shopify/ProductOption/1064576523\"}],\"price\":29.5}]", "typeKind": "MUTATION" } ] } ]