Insert Product with Multiple Variants

Insert Product with Multiple Variants

sumato47
Shopify Partner
1 0 0

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<ActionResult> 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();

"

Replies 0 (0)