Version: 2024-10
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" 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" 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" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<\"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" 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" Graphql 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}"
input: { "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.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 } ] }
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" } ] } ] } } }