1/25/2025

Shopify GraphQL: How to Add Multiple Variants to a Single Product

Managing product variants in Shopify can be a bit of a puzzle, especially when using the powerful but sometimes tricky GraphQL API. If you're wondering how to add multiple variants to a single product, hang tight! We're diving deep into this topic to make it as clear as a sunny day.

Introduction to Shopify GraphQL

Shopify's GraphQL API allows developers to interact with Shopify data efficiently and flexibly. This API offers a modern approach to querying data, as opposed to the traditional REST API, which can often be slower due to multiple requests being necessary. So, whether you’re a developer or just a curious mind, let's break down the steps to add multiple variants to a product using GraphQL.

Understanding Product Variants

Before diving into the code, let’s clarify what we mean by variants. In Shopify, a product can have multiple variants, which are essentially the different options available for that product. For example, if you sell a T-shirt, the variants could be different sizes and colors. Each variant can have its own price, SKU, inventory level, and more.

Important Terms:

  • SKU (Stock Keeping Unit): A unique identifier for each product or variant.
  • Barcode: A code printed on a label that can be scanned.
  • Inventory Item: The actual stock of a product or variant.

Step-by-Step Guide to Adding Multiple Variants

Let's break down the process of adding multiple variants to a single product into simple steps:

Step 1: Create the Product

First off, we need to create the product itself. This is done using the
1 productCreate
mutation. Here's an example of how you might structure your mutation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 mutation productCreate($input: ProductInput!) { productCreate(input: $input) { product { id title variants(first: 5) { edges { node { id title price sku } } } } userErrors { field message } } }
In your variables, you could structure it as follows:
1 2 3 4 5 6 7 8 9 10 11 12 { "input": { "title": "Cool T-Shirt", "variants": [ { "title": "Small - Red", "sku": "CTR-S", "price": "20.00" }, { "title": "Medium - Red", "sku": "CTR-M", "price": "20.00" }, { "title": "Large - Red", "sku": "CTR-L", "price": "20.00" }, { "title": "Small - Blue", "sku": "CTB-S", "price": "20.00" }, { "title": "Medium - Blue", "sku": "CTB-M", "price": "20.00" } ] } }

Step 2: Add Variants After Product Creation

Once your product is created, you may find that the default variant structure provided doesn’t meet your needs. In this case, you can use the
1 productVariantsBulkCreate
mutation to add models after the product creation process. Here's how you can do that:
1 2 3 4 5 6 7 8 9 10 11 12 13 mutation productVariantsBulkCreate($input: [ProductVariantInput!]!) { productVariantsBulkCreate(input: $input) { productVariants { id title price } userErrors { field message } } }
Your variables might look something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 { "input": [ { "productId": "gid://shopify/Product/123456789", "title": "Extra-Large - Red", "sku": "CTR-XL", "price": "22.00" }, { "productId": "gid://shopify/Product/123456789", "title": "Extra-Large - Blue", "sku": "CTB-XL", "price": "22.00" } ] }

Common Issues: Handling Errors

When you attempt to create multiple variants, make sure to handle errors appropriately. Issues such as duplicate titles or SKUs can cause the mutation to fail. Always check the
1 userErrors
response field to see if there are any problems.

Sample Query for Checking Variants

After adding your variants, you might want to verify that everything was set up correctly. You can do this by querying the product and its variants:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 query getProductWithVariants($id: ID!) { product(id: $id) { id title variants(first: 10) { edges { node { id title price } } } } }

Step 3: Updating Variants

Once you've got your variants created, chances are you'll need to update them at some point. This can include changing prices, adding new SKUs, or modifying titles. The
1 productVariantUpdate
mutation allows you to make those changes.
1 2 3 4 5 6 7 8 9 10 11 12 13 mutation productVariantUpdate($input: ProductVariantInput!) { productVariantUpdate(input: $input) { productVariant { id title price } userErrors { field message } } }

Step 4: Deleting Variants

If you need to remove a variant, make sure you’re cautious as deleting a variant can have consequences. Use the
1 productVariantDelete
mutation to accomplish this task:
1 2 3 4 5 6 7 8 9 mutation productVariantDelete($id: ID!) { productVariantDelete(input: { id: $id }) { deletedVariantId userErrors { field message } } }

Example Use Case

To make it clearer, let’s say we have a T-shirt product that comes in various colors and sizes. Using the steps and queries described, you could create this product with multiple size variants and update them as needed for sales periods or restocks.

Leveraging Arsturn to Enhance Your Shopify Store

Building out product variants is a crucial step in providing a rich shopping experience for your customers. But handling all the technical details can be a headache. That’s where Arsturn comes into play! With Arsturn, you can build a custom chatbot tailored to your brand which can handle FAQs about products, sizes, and variants. This allows potential customers to engage with the store without needing human oversight 24/7.
ARSTURN empowers you to create interactive chat experiences that can directly impact conversions. Ready to step up your engagement game? Get started with Arsturn today!

Conclusion

Adding multiple variants to a single product in Shopify using GraphQL is a straightforward process when you break it down into manageable steps. With mutations for creating, updating, and deleting variants, you have full control over your product offerings. Don't forget to leverage tools like Arsturn to enhance customer experience and drive sales. Get out there, optimize your store, and offer an exceptional shopping experience today!

Arsturn.com/
Claim your chatbot

Copyright © Arsturn 2025