Insert Product with Multiple Variants

Topic summary

A developer is encountering a 422 error when creating Shopify products with multiple variants through the ShopifySharp library. The error message states “The variant ‘Default Title’ already exists,” despite assigning different titles to each variant.

Technical Details:

  • Single-variant products create successfully
  • Multi-variant products trigger the error
  • Code attempts to create a product with two variants, each having distinct SKUs, titles, and prices

Code Structure:

  • Uses ShopifySharp client library
  • Defines variants with properties: SKU, Title, and Price
  • Example variants: “Obama-Shoes” ($10.99) and “Obama-Shirt” ($15.99)

Issue Status:
The problem remains unresolved. The code snippet appears partially corrupted or reversed in the original post, which may indicate formatting issues in the implementation. The developer is seeking assistance to resolve the duplicate variant error.

Summarized with AI on November 9. AI used: claude-sonnet-4-5-20250929.

Hey I need some help
When I am creating a product which have one variant it is created successfully,But when I am creating a product which have multiple variants it shows me this error

“ShopifySharp.Infrastructure.ShopifyHttpException: ‘(422 Unprocessable Entity) base: The variant ‘Default Title’ already exists.’”

Since I am giving different title of variants

this is my code

"

public async Task Index()
{
try
{
var shopifyService = new ShopifyClient(ShopDomain, Token);

// Create first product with two variants
var product1 = new ShopifySharp.Product()
{
Title = “Obama Grocery”,
BodyHtml = “Description for Product 1”,
Variants = new List<ShopifySharp.ProductVariant>
{
new ShopifySharp.ProductVariant { SKU = “P1-Variant1-SKU”, Title = “Obama-Shoes”, Price = 10.99m },
new ShopifySharp.ProductVariant { SKU = “P1-Variant2-SKU”, Title = “Obama-Shirt”, Price = 15.99m }
}
};

// Create the product asynchronously
await shopifyService.CreateProductAsync(product1);
}
catch (Exception ex)
{
// Log the exception
ViewBag.ErrorMessage = "An error occurred while creating products: " + ex.Message;
}

return View();

"