Version: 2024-01
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-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) { product { id } productVariants { id metafields(first: 1) { edges { node { namespace key value } } } } userErrors { field message } } }\",\n \"variables\": {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"options\": [\n \"Fashionable\"\n ],\n \"metafields\": [\n {\n \"namespace\": \"my_fields\",\n \"key\": \"liner_material\",\n \"type\": \"single_line_text_field\",\n \"value\": \"Synthetic Leather\"\n }\n ]\n },\n {\n \"options\": [\n \"Rugged\"\n ],\n \"metafields\": [\n {\n \"namespace\": \"my_fields\",\n \"key\": \"liner_material\",\n \"type\": \"single_line_text_field\",\n \"value\": \"Reinforced Polyethylene\"\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 productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\n product {\n id\n }\n productVariants {\n id\n metafields(first: 1) {\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 \"options\": [\n \"Fashionable\"\n ],\n \"metafields\": [\n {\n \"namespace\": \"my_fields\",\n \"key\": \"liner_material\",\n \"type\": \"single_line_text_field\",\n \"value\": \"Synthetic Leather\"\n }\n ]\n },\n {\n \"options\": [\n \"Rugged\"\n ],\n \"metafields\": [\n {\n \"namespace\": \"my_fields\",\n \"key\": \"liner_material\",\n \"type\": \"single_line_text_field\",\n \"value\": \"Reinforced Polyethylene\"\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 productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\n product {\n id\n }\n productVariants {\n id\n metafields(first: 1) {\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\": [{\"options\"=>[\"Fashionable\"], \"metafields\"=>[{\"namespace\"=>\"my_fields\", \"key\"=>\"liner_material\", \"type\"=>\"single_line_text_field\", \"value\"=>\"Synthetic Leather\"}]}, {\"options\"=>[\"Rugged\"], \"metafields\"=>[{\"namespace\"=>\"my_fields\", \"key\"=>\"liner_material\", \"type\"=>\"single_line_text_field\", \"value\"=>\"Reinforced Polyethylene\"}]}]\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 product {\n id\n }\n productVariants {\n id\n metafields(first: 1) {\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\n$variables = [\n \"productId\" => \"gid://shopify/Product/20995642\",\n \"variants\" => [{\"options\"=>[\"Fashionable\"], \"metafields\"=>[{\"namespace\"=>\"my_fields\", \"key\"=>\"liner_material\", \"type\"=>\"single_line_text_field\", \"value\"=>\"Synthetic Leather\"}]}, {\"options\"=>[\"Rugged\"], \"metafields\"=>[{\"namespace\"=>\"my_fields\", \"key\"=>\"liner_material\", \"type\"=>\"single_line_text_field\", \"value\"=>\"Reinforced Polyethylene\"}]}],\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 product {\n id\n }\n productVariants {\n id\n metafields(first: 1) {\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 \"options\": [\n \"Fashionable\"\n ],\n \"metafields\": [\n {\n \"namespace\": \"my_fields\",\n \"key\": \"liner_material\",\n \"type\": \"single_line_text_field\",\n \"value\": \"Synthetic Leather\"\n }\n ]\n },\n {\n \"options\": [\n \"Rugged\"\n ],\n \"metafields\": [\n {\n \"namespace\": \"my_fields\",\n \"key\": \"liner_material\",\n \"type\": \"single_line_text_field\",\n \"value\": \"Reinforced Polyethylene\"\n }\n ]\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 product {\n id\n }\n productVariants {\n id\n metafields(first: 1) {\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": [ { "options": [ "Fashionable" ], "metafields": [ { "namespace": "my_fields", "key": "liner_material", "type": "single_line_text_field", "value": "Synthetic Leather" } ] }, { "options": [ "Rugged" ], "metafields": [ { "namespace": "my_fields", "key": "liner_material", "type": "single_line_text_field", "value": "Reinforced Polyethylene" } ] } ] }
response: { "data": { "productVariantsBulkCreate": { "product": { "id": "gid://shopify/Product/20995642" }, "productVariants": [ { "id": "gid://shopify/ProductVariant/1070325175", "metafields": { "edges": [ { "node": { "namespace": "my_fields", "key": "liner_material", "value": "Synthetic Leather" } } ] } }, { "id": "gid://shopify/ProductVariant/1070325176", "metafields": { "edges": [ { "node": { "namespace": "my_fields", "key": "liner_material", "value": "Reinforced Polyethylene" } } ] } } ], "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation CreateProductVariantsInBulkAndMediaAttachedToVariants($productId: ID!, $variants: [ProductVariantsBulkInput!]!, $media: [CreateMediaInput!]) { productVariantsBulkCreate(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/912855135\",\n \"variants\": [\n {\n \"options\": [\n \"one\"\n ],\n \"sku\": \"AAA\",\n \"mediaSrc\": \"https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png\"\n },\n {\n \"options\": [\n \"two\"\n ],\n \"sku\": \"BBB\"\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 CreateProductVariantsInBulkAndMediaAttachedToVariants($productId: ID!, $variants: [ProductVariantsBulkInput!]!, $media: [CreateMediaInput!]) {\n productVariantsBulkCreate(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/912855135\",\n \"variants\": [\n {\n \"options\": [\n \"one\"\n ],\n \"sku\": \"AAA\",\n \"mediaSrc\": \"https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png\"\n },\n {\n \"options\": [\n \"two\"\n ],\n \"sku\": \"BBB\"\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 CreateProductVariantsInBulkAndMediaAttachedToVariants($productId: ID!, $variants: [ProductVariantsBulkInput!]!, $media: [CreateMediaInput!]) {\n productVariantsBulkCreate(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/912855135\",\n \"variants\": [{\"options\"=>[\"one\"], \"sku\"=>\"AAA\", \"mediaSrc\"=>\"https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png\"}, {\"options\"=>[\"two\"], \"sku\"=>\"BBB\"}],\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 = <<<QUERY\n mutation CreateProductVariantsInBulkAndMediaAttachedToVariants($productId: ID!, $variants: [ProductVariantsBulkInput!]!, $media: [CreateMediaInput!]) {\n productVariantsBulkCreate(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\n$variables = [\n \"productId\" => \"gid://shopify/Product/912855135\",\n \"variants\" => [{\"options\"=>[\"one\"], \"sku\"=>\"AAA\", \"mediaSrc\"=>\"https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png\"}, {\"options\"=>[\"two\"], \"sku\"=>\"BBB\"}],\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 CreateProductVariantsInBulkAndMediaAttachedToVariants($productId: ID!, $variants: [ProductVariantsBulkInput!]!, $media: [CreateMediaInput!]) {\n productVariantsBulkCreate(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/912855135\",\n \"variants\": [\n {\n \"options\": [\n \"one\"\n ],\n \"sku\": \"AAA\",\n \"mediaSrc\": \"https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png\"\n },\n {\n \"options\": [\n \"two\"\n ],\n \"sku\": \"BBB\"\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 CreateProductVariantsInBulkAndMediaAttachedToVariants($productId: ID!, $variants: [ProductVariantsBulkInput!]!, $media: [CreateMediaInput!]) {\n productVariantsBulkCreate(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/912855135", "variants": [ { "options": [ "one" ], "sku": "AAA", "mediaSrc": "https://cdn.shopify.com/shopifycloud/brochure/assets/sell/image/image-@artdirection-large-1ba8d5de56c361cec6bc487b747c8774b9ec8203f392a99f53c028df8d0fb3fc.png" }, { "options": [ "two" ], "sku": "BBB" } ], "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": { "productVariantsBulkCreate": { "product": { "id": "gid://shopify/Product/912855135", "media": { "nodes": [ { "id": "gid://shopify/MediaImage/1072273226", "alt": "Gray helmet for bikers", "mediaContentType": "IMAGE", "preview": { "status": "UPLOADED" } }, { "id": "gid://shopify/ExternalVideo/1072273227", "alt": "Testing helmet resistance against impacts", "mediaContentType": "EXTERNAL_VIDEO", "preview": { "status": "UPLOADED" } } ] } }, "productVariants": [ { "id": "gid://shopify/ProductVariant/1070325185", "sku": "AAA", "media": { "nodes": [ { "id": "gid://shopify/MediaImage/1072273226", "alt": "Gray helmet for bikers", "mediaContentType": "IMAGE", "preview": { "status": "UPLOADED" } } ] } }, { "id": "gid://shopify/ProductVariant/1070325186", "sku": "BBB", "media": { "nodes": [] } } ], "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation CreateProductVariantsInBulkWithExistingMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!) { productVariantsBulkCreate(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 \"options\": [\n \"one\"\n ],\n \"mediaId\": \"gid://shopify/MediaImage/730211239\"\n },\n {\n \"options\": [\n \"two\"\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 CreateProductVariantsInBulkWithExistingMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(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 \"options\": [\n \"one\"\n ],\n \"mediaId\": \"gid://shopify/MediaImage/730211239\"\n },\n {\n \"options\": [\n \"two\"\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 CreateProductVariantsInBulkWithExistingMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(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\": [{\"options\"=>[\"one\"], \"mediaId\"=>\"gid://shopify/MediaImage/730211239\"}, {\"options\"=>[\"two\"]}]\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 CreateProductVariantsInBulkWithExistingMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(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\n$variables = [\n \"productId\" => \"gid://shopify/Product/20995642\",\n \"variants\" => [{\"options\"=>[\"one\"], \"mediaId\"=>\"gid://shopify/MediaImage/730211239\"}, {\"options\"=>[\"two\"]}],\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 CreateProductVariantsInBulkWithExistingMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(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 \"options\": [\n \"one\"\n ],\n \"mediaId\": \"gid://shopify/MediaImage/730211239\"\n },\n {\n \"options\": [\n \"two\"\n ]\n }\n ]\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation CreateProductVariantsInBulkWithExistingMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(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": [ { "options": [ "one" ], "mediaId": "gid://shopify/MediaImage/730211239" }, { "options": [ "two" ] } ] }
response: { "data": { "productVariantsBulkCreate": { "product": { "id": "gid://shopify/Product/20995642" }, "productVariants": [ { "id": "gid://shopify/ProductVariant/1070325173", "title": "one", "media": { "nodes": [ { "id": "gid://shopify/MediaImage/730211239", "alt": "a snowboard", "mediaContentType": "IMAGE", "preview": { "status": "READY" } } ] } }, { "id": "gid://shopify/ProductVariant/1070325174", "title": "two", "media": { "nodes": [] } } ], "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-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) { product { id } productVariants { id title price compareAtPrice } userErrors { field message } } }\",\n \"variables\": {\n \"productId\": \"gid://shopify/Product/-1\",\n \"variants\": [\n {\n \"options\": [\n \"Golden\"\n ],\n \"price\": 15.99,\n \"compareAtPrice\": 19.99\n },\n {\n \"options\": [\n \"Silver\"\n ],\n \"price\": 13.99,\n \"compareAtPrice\": null\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 product {\n id\n }\n productVariants {\n id\n title\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"productId\": \"gid://shopify/Product/-1\",\n \"variants\": [\n {\n \"options\": [\n \"Golden\"\n ],\n \"price\": 15.99,\n \"compareAtPrice\": 19.99\n },\n {\n \"options\": [\n \"Silver\"\n ],\n \"price\": 13.99,\n \"compareAtPrice\": null\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 product {\n id\n }\n productVariants {\n id\n title\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"productId\": \"gid://shopify/Product/-1\",\n \"variants\": [{\"options\"=>[\"Golden\"], \"price\"=>15.99, \"compareAtPrice\"=>19.99}, {\"options\"=>[\"Silver\"], \"price\"=>13.99, \"compareAtPrice\"=>nil}]\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 product {\n id\n }\n productVariants {\n id\n title\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY;\n\n$variables = [\n \"productId\" => \"gid://shopify/Product/-1\",\n \"variants\" => [{\"options\"=>[\"Golden\"], \"price\"=>15.99, \"compareAtPrice\"=>19.99}, {\"options\"=>[\"Silver\"], \"price\"=>13.99, \"compareAtPrice\"=>nil}],\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 product {\n id\n }\n productVariants {\n id\n title\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"productId\": \"gid://shopify/Product/-1\",\n \"variants\": [\n {\n \"options\": [\n \"Golden\"\n ],\n \"price\": 15.99,\n \"compareAtPrice\": 19.99\n },\n {\n \"options\": [\n \"Silver\"\n ],\n \"price\": 13.99,\n \"compareAtPrice\": null\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 product {\n id\n }\n productVariants {\n id\n title\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "productId": "gid://shopify/Product/-1", "variants": [ { "options": [ "Golden" ], "price": 15.99, "compareAtPrice": 19.99 }, { "options": [ "Silver" ], "price": 13.99, "compareAtPrice": null } ] }
response: { "data": { "productVariantsBulkCreate": { "product": null, "productVariants": [], "userErrors": [ { "field": [ "productId" ], "message": "Product does not exist" } ] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-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) { product { id } productVariants { id title price compareAtPrice } userErrors { field message } } }\",\n \"variables\": {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"options\": [\n \"Golden\"\n ],\n \"price\": 15.99,\n \"compareAtPrice\": 19.99\n },\n {\n \"options\": [\n \"Silver\"\n ],\n \"price\": 15.99,\n \"compareAtPrice\": null\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 product {\n id\n }\n productVariants {\n id\n title\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"options\": [\n \"Golden\"\n ],\n \"price\": 15.99,\n \"compareAtPrice\": 19.99\n },\n {\n \"options\": [\n \"Silver\"\n ],\n \"price\": 15.99,\n \"compareAtPrice\": null\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 product {\n id\n }\n productVariants {\n id\n title\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [{\"options\"=>[\"Golden\"], \"price\"=>15.99, \"compareAtPrice\"=>19.99}, {\"options\"=>[\"Silver\"], \"price\"=>15.99, \"compareAtPrice\"=>nil}]\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 product {\n id\n }\n productVariants {\n id\n title\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY;\n\n$variables = [\n \"productId\" => \"gid://shopify/Product/20995642\",\n \"variants\" => [{\"options\"=>[\"Golden\"], \"price\"=>15.99, \"compareAtPrice\"=>19.99}, {\"options\"=>[\"Silver\"], \"price\"=>15.99, \"compareAtPrice\"=>nil}],\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 product {\n id\n }\n productVariants {\n id\n title\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"productId\": \"gid://shopify/Product/20995642\",\n \"variants\": [\n {\n \"options\": [\n \"Golden\"\n ],\n \"price\": 15.99,\n \"compareAtPrice\": 19.99\n },\n {\n \"options\": [\n \"Silver\"\n ],\n \"price\": 15.99,\n \"compareAtPrice\": null\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 product {\n id\n }\n productVariants {\n id\n title\n price\n compareAtPrice\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "productId": "gid://shopify/Product/20995642", "variants": [ { "options": [ "Golden" ], "price": 15.99, "compareAtPrice": 19.99 }, { "options": [ "Silver" ], "price": 15.99, "compareAtPrice": null } ] }
response: { "data": { "productVariantsBulkCreate": { "product": { "id": "gid://shopify/Product/20995642" }, "productVariants": [ { "id": "gid://shopify/ProductVariant/1070325183", "title": "Golden", "price": "15.99", "compareAtPrice": "19.99" }, { "id": "gid://shopify/ProductVariant/1070325184", "title": "Silver", "price": "15.99", "compareAtPrice": null } ], "userErrors": [] } } }