Skip to main content
Published: May 04 2011, 2:14:00 AMUpdated: November 28 2020, 9:25:30 PM

C# AddFixedPriceItem sample for multi-variation listings for AU. This has been written using the .NET SDK v715.

 

Multi-variation listings contain items that are logically the same product, but that vary in their manufacturing details or packaging.

Below is the code. Corresponding SOAP request is attached with this article.

/* 2012-2013 eBay Inc., All Rights Reserved */
/* Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php */

using eBay.Service.Call;
using eBay.Service.Core.Sdk;
using eBay.Service.Util;
using eBay.Service.Core.Soap;

namespace Trading_Samples
{
public class AddFixedPriceItem
{
//AddFPItem - multi-variation items
private static void AddFPItemWithVariations()
        {

            //create the context
            ApiContext context = new ApiContext();

            //set the User token
            context.ApiCredential.eBayToken = "Your Token";

            //set the server url
            context.SoapApiServerUrl = "https://api.sandbox.ebay.com/wsapi";

            //enable logging
            context.ApiLogManager = new ApiLogManager();
            context.ApiLogManager.ApiLoggerList.Add(new FileLogger("../../log.txt", true, true, true));
            context.ApiLogManager.EnableLogging = true;

            //set the version
            context.Version = "705";
            context.Site = SiteCodeType.Australia;

            //create the call object
            AddFixedPriceItemCall AddFPItemCall = new AddFixedPriceItemCall(context);

            AddFPItemCall.AutoSetItemUUID = true;

            //create an item object and set the properties
            ItemType item = new ItemType();

            //set the item condition depending on the value from GetCategoryFeatures
            item.ConditionID = 1000; //new with tags

            //Basic properties of a listing
            item.Country = CountryCodeType.AU;
            item.Currency = CurrencyCodeType.AUD;

            //Track item by SKU
            item.InventoryTrackingMethod = InventoryTrackingMethodCodeType.SKU;

            //Parent Level SKU
            item.SKU = "VARPARENT";

            item.Description = "test - do not bid or buy";
            item.Title = "test - do not bid or buy";
            item.SubTitle = "Test Item";
            item.ListingDuration = "Days_7";

            item.PaymentMethods = new BuyerPaymentMethodCodeTypeCollection();
            item.PaymentMethods.Add(BuyerPaymentMethodCodeType.PayPal);
            item.PayPalEmailAddress = "test@test.com";
            item.Location = "Australia";

            //Specify Shipping Services
            item.DispatchTimeMax = 3;
            item.ShippingDetails = new ShippingDetailsType();
            item.ShippingDetails.ShippingServiceOptions = new ShippingServiceOptionsTypeCollection();

            ShippingServiceOptionsType shipservice1 = new ShippingServiceOptionsType();
            shipservice1.ShippingService = "AU_Courier";
            shipservice1.ShippingServicePriority = 1;
            shipservice1.ShippingServiceCost = new AmountType();
            shipservice1.ShippingServiceCost.currencyID = CurrencyCodeType.AUD;
            shipservice1.ShippingServiceCost.Value = 1.0;

            shipservice1.ShippingServiceAdditionalCost = new AmountType();
            shipservice1.ShippingServiceAdditionalCost.currencyID = CurrencyCodeType.AUD;
            shipservice1.ShippingServiceAdditionalCost.Value = 1.0;

            item.ShippingDetails.ShippingServiceOptions.Add(shipservice1);

            ShippingServiceOptionsType shipservice2 = new ShippingServiceOptionsType();
            shipservice2.ShippingService = "AU_Express";
            shipservice2.ShippingServicePriority = 2;
            shipservice2.ShippingServiceCost = new AmountType();
            shipservice2.ShippingServiceCost.currencyID = CurrencyCodeType.AUD;
            shipservice2.ShippingServiceCost.Value = 4.0;

            shipservice2.ShippingServiceAdditionalCost = new AmountType();
            shipservice2.ShippingServiceAdditionalCost.currencyID = CurrencyCodeType.AUD;
            shipservice2.ShippingServiceAdditionalCost.Value = 1.0;

            item.ShippingDetails.ShippingServiceOptions.Add(shipservice2);

            //Specify Return Policy
            item.ReturnPolicy = new ReturnPolicyType();
            item.ReturnPolicy.ReturnsAcceptedOption = "ReturnsAccepted";

            item.PrimaryCategory = new CategoryType();
            item.PrimaryCategory.CategoryID = "57991";

            //Add Item Specifics
            item.ItemSpecifics = new NameValueListTypeCollection();

            NameValueListTypeCollection ItemSpecs = new NameValueListTypeCollection();

            NameValueListType nv1 = new NameValueListType();
            StringCollection valueCol1 = new StringCollection();

            nv1.Name = "Brand";
            valueCol1.Add("Ralph Lauren");
            nv1.Value = valueCol1;
            ItemSpecs.Add(nv1);

            item.ItemSpecifics = ItemSpecs;

            //Specify VariationSpecificsSet
            item.Variations = new VariationsType();

            item.Variations.VariationSpecificsSet = new NameValueListTypeCollection();

            NameValueListType NVListVS1 = new NameValueListType();
            NVListVS1.Name = "Size";
            StringCollection VSvaluecollection1 = new StringCollection();
            String[] Size = { "XS", "S", "M", "L", "XL" };
            VSvaluecollection1.AddRange(Size);

            NVListVS1.Value = VSvaluecollection1;
            item.Variations.VariationSpecificsSet.Add(NVListVS1);

            NameValueListType NVListVS2 = new NameValueListType();
            NVListVS2.Name = "Colour";
            StringCollection VSvaluecollection2 = new StringCollection();
            String[] Colour = { "Black", "Blue" };
            VSvaluecollection2.AddRange(Colour);

            NVListVS2.Value = VSvaluecollection2;
            item.Variations.VariationSpecificsSet.Add(NVListVS2);


            //Specify Variations
            VariationTypeCollection VarCol = new VariationTypeCollection();

            //Variation 1 - Black S
            VariationType var1 = new VariationType();
            var1.SKU = "VAR1";
            var1.Quantity = 10;
            var1.StartPrice = new AmountType();
            var1.StartPrice.currencyID = CurrencyCodeType.AUD;
            var1.StartPrice.Value = 35;
            var1.VariationSpecifics = new NameValueListTypeCollection();

            NameValueListType Var1Spec1 = new NameValueListType();
            StringCollection Var1Spec1Valuecoll = new StringCollection();

            Var1Spec1.Name = "Colour";
            Var1Spec1Valuecoll.Add("Black");
            Var1Spec1.Value = Var1Spec1Valuecoll;

            var1.VariationSpecifics.Add(Var1Spec1);

            NameValueListType Var1Spec2 = new NameValueListType();
            StringCollection Var1Spec2Valuecoll = new StringCollection();

            Var1Spec2.Name = "Size";
            Var1Spec2Valuecoll.Add("S");
            Var1Spec2.Value = Var1Spec2Valuecoll;

            var1.VariationSpecifics.Add(Var1Spec2);

            VarCol.Add(var1);

            //Variation 2 - Black L
            VariationType var2 = new VariationType();
            var2.SKU = "VAR2";
            var2.Quantity = 10;
            var2.StartPrice = new AmountType();
            var2.StartPrice.currencyID = CurrencyCodeType.AUD;
            var2.StartPrice.Value = 45;

            var2.VariationSpecifics = new NameValueListTypeCollection();

            NameValueListType Var2Spec1 = new NameValueListType();
            StringCollection Var2Spec1Valuecoll = new StringCollection();

            Var2Spec1.Name = "Colour";
            Var2Spec1Valuecoll.Add("Black");
            Var2Spec1.Value = Var2Spec1Valuecoll;

            var2.VariationSpecifics.Add(Var2Spec1);

            NameValueListType Var2Spec2 = new NameValueListType();
            StringCollection Var2Spec2Valuecoll = new StringCollection();

            Var2Spec2.Name = "Size";
            Var2Spec2Valuecoll.Add("L");
            Var2Spec2.Value = Var2Spec2Valuecoll;

            var2.VariationSpecifics.Add(Var2Spec2);

            VarCol.Add(var2);

            //Variation 3 - Blue M
            VariationType var3 = new VariationType();
            var3.SKU = "VAR3";
            var3.Quantity = 10;
            var3.StartPrice = new AmountType();
            var3.StartPrice.currencyID = CurrencyCodeType.AUD;
            var3.StartPrice.Value = 40;

            var3.VariationSpecifics = new NameValueListTypeCollection();

            NameValueListType Var3Spec1 = new NameValueListType();
            StringCollection Var3Spec1Valuecoll = new StringCollection();

            Var3Spec1.Name = "Colour";
            Var3Spec1Valuecoll.Add("Blue");
            Var3Spec1.Value = Var3Spec1Valuecoll;

            var3.VariationSpecifics.Add(Var3Spec1);

            NameValueListType Var3Spec2 = new NameValueListType();
            StringCollection Var3Spec2Valuecoll = new StringCollection();

            Var3Spec2.Name = "Size";
            Var3Spec2Valuecoll.Add("M");
            Var3Spec2.Value = Var3Spec2Valuecoll;

            var3.VariationSpecifics.Add(Var3Spec2);

            VarCol.Add(var3);

            //Variation 4 - Blue L
            VariationType var4 = new VariationType();
            var4.SKU = "VAR4";
            var4.Quantity = 10;
            var4.StartPrice = new AmountType();
            var4.StartPrice.currencyID = CurrencyCodeType.AUD;
            var4.StartPrice.Value = 45;

            var4.VariationSpecifics = new NameValueListTypeCollection();

            NameValueListType Var4Spec1 = new NameValueListType();
            StringCollection Var4Spec1Valuecoll = new StringCollection();

            Var4Spec1.Name = "Colour";
            Var4Spec1Valuecoll.Add("Blue");
            Var4Spec1.Value = Var4Spec1Valuecoll;

            var4.VariationSpecifics.Add(Var4Spec1);

            NameValueListType Var4Spec2 = new NameValueListType();
            StringCollection Var4Spec2Valuecoll = new StringCollection();

            Var4Spec2.Name = "Size";
            Var4Spec2Valuecoll.Add("L");
            Var4Spec2.Value = Var4Spec2Valuecoll;

            var4.VariationSpecifics.Add(Var4Spec2);

            VarCol.Add(var4);

            //Add Variation Specific Pictures
            item.Variations.Pictures = new PicturesTypeCollection();

            PicturesType pic = new PicturesType();
            pic.VariationSpecificName = "Colour";
            pic.VariationSpecificPictureSet = new VariationSpecificPictureSetTypeCollection();

            VariationSpecificPictureSetType VarPicSet1 = new VariationSpecificPictureSetType();
            VarPicSet1.VariationSpecificValue = "Black";
            StringCollection PicURLVarPicSet1 = new StringCollection();
            PicURLVarPicSet1.Add("http://i12.ebayimg.com/03/i/04/8a/5f/a1_1_sbl.JPG");
            VarPicSet1.PictureURL = PicURLVarPicSet1;

            pic.VariationSpecificPictureSet.Add(VarPicSet1);

            VariationSpecificPictureSetType VarPicSet2 = new VariationSpecificPictureSetType();
            VarPicSet2.VariationSpecificValue = "Blue";
            StringCollection PicURLVarPicSet2 = new StringCollection();
            PicURLVarPicSet2.Add("http://i2.sandbox.ebayimg.com/03/i/00/3f/c5/92_1.JPG?set_id=8800004005");
            VarPicSet2.PictureURL = PicURLVarPicSet2;

            pic.VariationSpecificPictureSet.Add(VarPicSet2);

            item.Variations.Pictures.Add(pic);

            item.Variations.Variation = VarCol;

            //Add item level pictures
            item.PictureDetails = new PictureDetailsType();
            item.PictureDetails.PictureURL = new StringCollection();
            item.PictureDetails.PictureURL.Add("http://i2.sandbox.ebayimg.com/03/i/00/3f/c5/92_1.JPG?set_id=8800004005");
            item.PictureDetails.PhotoDisplay = PhotoDisplayCodeType.SuperSize;
            item.PictureDetails.PhotoDisplaySpecified = true;

            AddFPItemCall.Item = item;

            //set the item and make the call
            AddFPItemCall.Execute();

            Console.WriteLine(AddFPItemCall.ApiResponse.Ack + " " + AddFPItemCall.ApiResponse.ItemID);
        }

}

}

How well did this answer your question?
Answers others found helpful