Home > Articles > Home & Office Computing > eBay/Yahoo/Google

  • Print
  • + Share This
Like this article? We recommend

Creating Listings

To list something, you'll start off with an instance of Item, which must be fully populated with the auction information before posting to the eBay system with an instance of AddItemCall. The naming pattern ActionObjectCall is used throughout the eBay API, so if you're looking for a class that will allow you to, say, get information on a user, you'll know that the class you need is GetUserCall. For a list of sellers, the object would be GetSellerListCall.

The Item object has a huge assortment of fields that can be set to describe it, many of which are not needed in most cases. However, you'll want to assign it to the correct category each time. The following code will retrieve the complete list of categories:

GetCategoriesCall catCall = new GetCategoriesCall(session);
ICategoryCollection cats = null;
catCall.SiteId = SiteIdEnum.US;
catCall.LevelLimit = 4;
catCall.ViewAllNodes = true;

{ cats = catCall.GetCategories(); }
catch (Exception e)
{ /*Handle Exception*/ }

System.Console.WriteLine("Categories: " + cats.Count);

Each category has a CategoryName and a CategoryId. You can select your location to retrieve category names that are appropriate to your user base. The LevelLimit value here is important, as it indicates how far down the tree of nested categories this call should walk, each level having an exponentially higher number of categories than the previous level. At the time of writing, a call of level 2 retrieves about 500 categories, while a call at level 4 returns about 15,000!

Retrieving a subset of the categories each time is a slow process, so these should be cached locally. However, categories do change over time, and using an invalid category code results in a failed item insertion, so periodically the categories need to be refreshed.

For the listing itself, we need a few objects::

AddItemCall itemCall = new AddItemCall(session);
VerifyAddItemCall verifyCall = new VerifyAddItemCall(session);
Item item = new Item();

IFees fees = null;

The Item itself is empty at this point. AddItemCall is the object that will do the actual insertion, while VerifyItemCall can be used to do a test run, ensuring that we've set everything correctly and finding out how much listing this auction will cost before it goes live. But, before we can do that, the Item needs populating:

item.Title = "Test item";
item.Description = "Hello World!";

item.Uuid = new Uuid(true);
item.SiteId = SiteIdEnum.US;
item.Country = "us";
item.Location = "Albany, NY";
item.Currency = CurrencyEnum.USDollar;
item.Quantity = 1;
item.CategoryId = 357;
item.Type = ItemTypes.Auction;
item.StartPrice = 1.00m;
item.Duration = 7;
item.BuyItNowPrice = 10.00m;
item.PaymentTerms.SeeDescription = true;
item.ShippingOptions.ShippingRange = ShippingRangeEnum.WorldWide;
item.ShippingOptions.WhoPaysShipping = WhoPayShippingEnum.BuyerPays;

Uuid here is just a unique identifier for the item, easily created from the Uuid helper class. Many of the values here, such as Currency and ShippingRange, are integer values specified via a number of helper enumerations listing all valid values.

Once populated, it's time to find out how much the listing will cost, and to actually post it online:

verifyCall.ItemToAdd = item;
fees = verifyCall.VerifyAddItem();
System.Console.WriteLine("Pending Fees: " + fees.ListingFee);

itemCall.ItemToAdd = item;
fees = itemCall.AddItem();
System.Console.WriteLine("Fees Charged: " + fees.ListingFee);

In this example, we're simply printing out the cost of the item before doing the formal listing. In the real world, you'd likely want to confirm that the cost is acceptable before posting the item to the site. The verification also ensures that the CategoryId you've provided is valid, generally making sure that everything is in order before posting.

  • + Share This
  • 🔖 Save To Your Account