Making eBay SDK Calls
After creating the ApiSession object you use it to place other calls to the eBay SDK. To list an item, you first retrieve the item's data from the local inventory database, including the item's name, description, and perhaps other data about the item such as its physical location and selling price. For this sample application, you need only retrieve the item's name and description from the database using the following ADO.NET query:
Dim cn As IDbConnection = GetConnection()
Dim da As OleDbDataAdapter
Dim theSql As String
theSql = "SELECT ID, Name, Description " & _
"FROM tblProduct " & _
"WHERE ID = " & CurrentItemID
Dim ds As DataSet = New DataSet("Product")
da = New OleDbDataAdapter(theSql, cn)
The value CurrentItemID
in the preceding code fragment gets set when the user clicks on a row in the DataGrid control.
Now that you have the information about the item you want to list, you can send it off to eBay. Do this by first creating an instance of an IItem object (found in the eBay.SDK.Model.Item namespace). This object represents, not surprisingly, the item to be listed on eBay; it contains properties that describe the item and the item's listing format. The listing format is important, because not all eBay listings are auctions you can sell an item in a fixed-price format as well, a convenience that many buyers appreciate.
When I create an eBay SDK application, I typically create a function that specifically creates and returns an IItem. Here's an example of such a function:
Private Function CreateItem(ByVal title As
String, ByVal description As String) As IItem
Dim it As IItem = New eBay.SDK.Model.Item.Item
.SiteId = SiteIdEnum.US
.Type = ItemTypes.Auction
.Title = title
.Description = description
.Currency = CurrencyEnum.USDollar
.Location = "San Jose, CA"
.Country = "us"
.CategoryId = 14111 ' test auctions:general
.Quantity = 1
.Duration = 7
.MinimumToBid = 0.01
.BuyItNowPrice = 15.0
.ReservePrice = 0
.PaymentTerms.SeeDescription = True
.ShippingOptions.ShippingRange = _
.Uuid = New Uuid(True)
Obviously, in this example, many of the values are hard-coded. In a real application, you'd retrieve data for properties like Location
from the database, or perhaps even from the registry or App.Config
is an interesting property. This example uses eBay's test
category, which exists specifically for software developers and others who want to experiment. But eBay has more than 30,000 product categories, with more being added every month. If you want to incorporate this category hierarchy in your application, you can do so by downloading it in XML format (use the GetCategories
method to obtain the category list).