Version: 2025-01
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation ProductVariantsCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) { productVariantsBulkCreate(productId: $productId, variants: $variants) { productVariants { id title selectedOptions { name value } } userErrors { field message } } }\",\n \"variables\": {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"price\": 15.99,\n \"compareAtPrice\": 19.99,\n \"optionValues\": [\n {\n \"name\": \"Golden\",\n \"optionId\": \"gid://shopify/ProductOption/328272167\"\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 ProductVariantsCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\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/20995642\",\n \"variants\": [\n {\n \"price\": 15.99,\n \"compareAtPrice\": 19.99,\n \"optionValues\": [\n {\n \"name\": \"Golden\",\n \"optionId\": \"gid://shopify/ProductOption/328272167\"\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 ProductVariantsCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\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/20995642\",\n \"variants\": [{\"price\"=>15.99, \"compareAtPrice\"=>19.99, \"optionValues\"=>[{\"name\"=>\"Golden\", \"optionId\"=>\"gid://shopify/ProductOption/328272167\"}]}]\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 = <<<QUERY\n mutation ProductVariantsCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\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\n$variables = [\n \"productId\" => \"gid://shopify/Product/20995642\",\n \"variants\" => [{\"price\"=>15.99, \"compareAtPrice\"=>19.99, \"optionValues\"=>[{\"name\"=>\"Golden\", \"optionId\"=>\"gid://shopify/ProductOption/328272167\"}]}],\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 ProductVariantsCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\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/20995642\",\n \"variants\": [\n {\n \"price\": 15.99,\n \"compareAtPrice\": 19.99,\n \"optionValues\": [\n {\n \"name\": \"Golden\",\n \"optionId\": \"gid://shopify/ProductOption/328272167\"\n }\n ]\n }\n ]\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation ProductVariantsCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\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/20995642", "variants": [ { "price": 15.99, "compareAtPrice": 19.99, "optionValues": [ { "name": "Golden", "optionId": "gid://shopify/ProductOption/328272167" } ] } ] }
response: { "data": { "productVariantsBulkCreate": { "productVariants": [ { "id": "gid://shopify/ProductVariant/1070325177", "title": "Golden", "selectedOptions": [ { "name": "Title", "value": "Golden" } ] } ], "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2025-01/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/1072481066\",\n \"variants\": [\n {\n \"optionValues\": [\n {\n \"name\": \"Red\",\n \"optionName\": \"Color\"\n },\n {\n \"name\": \"Brand new style\",\n \"optionId\": \"gid://shopify/ProductOption/1064576530\"\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/1054672336\",\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/1064576530\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672337\",\n \"optionId\": \"gid://shopify/ProductOption/1064576529\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672339\",\n \"optionId\": \"gid://shopify/ProductOption/1064576531\"\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/1072481066\",\n \"variants\": [\n {\n \"optionValues\": [\n {\n \"name\": \"Red\",\n \"optionName\": \"Color\"\n },\n {\n \"name\": \"Brand new style\",\n \"optionId\": \"gid://shopify/ProductOption/1064576530\"\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/1054672336\",\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/1064576530\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672337\",\n \"optionId\": \"gid://shopify/ProductOption/1064576529\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672339\",\n \"optionId\": \"gid://shopify/ProductOption/1064576531\"\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/1072481066\",\n \"variants\": [{\"optionValues\"=>[{\"name\"=>\"Red\", \"optionName\"=>\"Color\"}, {\"name\"=>\"Brand new style\", \"optionId\"=>\"gid://shopify/ProductOption/1064576530\"}, {\"name\"=>\"Silk\", \"optionName\"=>\"Material\"}], \"price\"=>22.0}, {\"optionValues\"=>[{\"name\"=>\"Brand new style\", \"optionName\"=>\"Style\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672336\", \"optionName\"=>\"Color\"}, {\"name\"=>\"Silk\", \"optionName\"=>\"Material\"}], \"price\"=>23.5}, {\"optionValues\"=>[{\"name\"=>\"Brand new style\", \"optionId\"=>\"gid://shopify/ProductOption/1064576530\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672337\", \"optionId\"=>\"gid://shopify/ProductOption/1064576529\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672339\", \"optionId\"=>\"gid://shopify/ProductOption/1064576531\"}], \"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 = <<<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/1072481066\",\n \"variants\" => [{\"optionValues\"=>[{\"name\"=>\"Red\", \"optionName\"=>\"Color\"}, {\"name\"=>\"Brand new style\", \"optionId\"=>\"gid://shopify/ProductOption/1064576530\"}, {\"name\"=>\"Silk\", \"optionName\"=>\"Material\"}], \"price\"=>22.0}, {\"optionValues\"=>[{\"name\"=>\"Brand new style\", \"optionName\"=>\"Style\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672336\", \"optionName\"=>\"Color\"}, {\"name\"=>\"Silk\", \"optionName\"=>\"Material\"}], \"price\"=>23.5}, {\"optionValues\"=>[{\"name\"=>\"Brand new style\", \"optionId\"=>\"gid://shopify/ProductOption/1064576530\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672337\", \"optionId\"=>\"gid://shopify/ProductOption/1064576529\"}, {\"id\"=>\"gid://shopify/ProductOptionValue/1054672339\", \"optionId\"=>\"gid://shopify/ProductOption/1064576531\"}], \"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/1072481066\",\n \"variants\": [\n {\n \"optionValues\": [\n {\n \"name\": \"Red\",\n \"optionName\": \"Color\"\n },\n {\n \"name\": \"Brand new style\",\n \"optionId\": \"gid://shopify/ProductOption/1064576530\"\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/1054672336\",\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/1064576530\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672337\",\n \"optionId\": \"gid://shopify/ProductOption/1064576529\"\n },\n {\n \"id\": \"gid://shopify/ProductOptionValue/1054672339\",\n \"optionId\": \"gid://shopify/ProductOption/1064576531\"\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/1072481066", "variants": [ { "optionValues": [ { "name": "Red", "optionName": "Color" }, { "name": "Brand new style", "optionId": "gid://shopify/ProductOption/1064576530" }, { "name": "Silk", "optionName": "Material" } ], "price": 22.0 }, { "optionValues": [ { "name": "Brand new style", "optionName": "Style" }, { "id": "gid://shopify/ProductOptionValue/1054672336", "optionName": "Color" }, { "name": "Silk", "optionName": "Material" } ], "price": 23.5 }, { "optionValues": [ { "name": "Brand new style", "optionId": "gid://shopify/ProductOption/1064576530" }, { "id": "gid://shopify/ProductOptionValue/1054672337", "optionId": "gid://shopify/ProductOption/1064576529" }, { "id": "gid://shopify/ProductOptionValue/1054672339", "optionId": "gid://shopify/ProductOption/1064576531" } ], "price": 29.5 } ] }
response: { "data": { "productVariantsBulkCreate": { "userErrors": [], "product": { "id": "gid://shopify/Product/1072481066", "options": [ { "id": "gid://shopify/ProductOption/1064576529", "name": "Color", "values": [ "Blue", "Red" ], "position": 1, "optionValues": [ { "id": "gid://shopify/ProductOptionValue/1054672336", "name": "Blue", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054672337", "name": "Red", "hasVariants": true } ] }, { "id": "gid://shopify/ProductOption/1064576530", "name": "Style", "values": [ "Old style", "Brand new style" ], "position": 2, "optionValues": [ { "id": "gid://shopify/ProductOptionValue/1054672338", "name": "Old style", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054672341", "name": "Brand new style", "hasVariants": true } ] }, { "id": "gid://shopify/ProductOption/1064576531", "name": "Material", "values": [ "Polyester", "Silk" ], "position": 3, "optionValues": [ { "id": "gid://shopify/ProductOptionValue/1054672339", "name": "Polyester", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054672340", "name": "Silk", "hasVariants": true } ] } ] }, "productVariants": [ { "id": "gid://shopify/ProductVariant/1070325180", "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/1070325181", "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/1070325182", "title": "Red / Brand new style / Polyester", "selectedOptions": [ { "name": "Color", "value": "Red" }, { "name": "Style", "value": "Brand new style" }, { "name": "Material", "value": "Polyester" } ] } ] } } }