Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Integrate Your Inventory System with the eBay SDK : Page 4

eBay provides a Software Development Kit that makes it easy for .NET developers to create applications that incorporate the eBay marketplace. This article explains how to build a working example application that integrates with eBay.


advertisement
Sending an Item to eBay
Returning to the task at hand, you now have an ApiSession object that has your identity assigned to it, as well as an IItem object that has been populated with data. All that remains is to send the item to eBay. Here's how to do that:

Dim ai As AddItemCall = New AddItemCall(sess) With ai .ItemToAdd = it .ErrorLevel = _ ErrorLevelEnum.BothShortAndLongErrorStrings Try Dim fees As IFees = ai.AddItem() Status.Text = _ "Listed item successfully. " & _ "eBay item ID is " & ai.ItemToAdd.ItemId.ToString() & ". " & "Listing fee is " & fees.InsertionFee.ToString() & "." Catch ex As APIException MessageBox.Show("API exception in " & _ "AddItem. [" + ex.Message + "]") Catch ex As Exception MessageBox.Show("Exception in AddItem." & _ " [" + ex.Message + "]") End Try End With

To send the item to eBay, you create an instance of an API wrapper class called AddItemCall, passing the ApiSession object we created previously into the AddItemCall object's constructor. Then, assign the IItem object to the ItemToAdd property and tell the object that you want to receive verbose error data if anything goes wrong. Finally, start a Try...Catch block because you're about to subject the item to the vagaries of the Internet and you need to make sure that the application reports any errors that occur to the user in a reasonable fashion.

Interestingly, the AddItem method  returns a new kind of object, IFees. This object tells the user what it costs to list the item for sale on eBay.

If you've never used eBay to sell items, eBay charges sellers to list items at the time the item is listed and again when the item is sold. These charges don't apply when you're developing applications in the sandbox, of course, so feel free to list items there until the cows come home.

At this point you've cut the amount of time it takes to list an item from several minutes down to a few seconds. But the whole point here is to enable you to accelerate your business by blasting your inventory onto eBay. So how can you keep track of all the items you have for sale?

One method to retrieve a comprehensive list of all the items you've listed on eBay is to call the GetSellerList method. While it's possible and sometimes useful to retrieve this information as a typed collection, when displaying collections of IItem objects in Windows Forms I use a trick that lets my application get to the raw XML data behind the wrapper class. In VB.NET you do this by declaring the GetSellerListCall object using the WithEvents keyword, and then handling the OnReceiveResponseXml event of the GetSellerListCall object.

Here's the call to GetSellerList that retrieves all this data:

Private WithEvents slc As GetSellerListCall slc = New GetSellerListCall( _ sc.CreateSession()) With slc .Timeout = 60000 ' In the following line, ' 32 is a medium abbreviated result set .DetailLevel = 32 .EndTimeFrom = DateTime.Now.ToUniversalTime() .EndTimeTo = slc.EndTimeFrom.AddDays(120) .PageNumber = 1 .ItemsPerPage = 100 End With Dim items As IItemCollection items = slc.GetSellerList

Note that the DetailLevel property gives you have a number of options for retrieving data from eBay. You don't have to perform an excruciating call to repeatedly download the complete set of data associated with hundreds of items; it's better to choose a specific detail level to retrieve only that information you need. For example, detail level 2 retrieves the eBay IDs for all the items you're selling (and not much else). So if you cleverly stored the eBay ID for the listing somewhere in your database at the time you listed the item, you don't have to call the heavyweight version of GetSellerList over and over again to retrieve information you already have. When you're jumping across the Internet to retrieve large XML result sets, it's handy to have some granular control over how much data gets retrieved for each context.

If you want to see the item page on eBay (to bid on it, perhaps, or to see how your listing looks), you can launch an instance of the default Web browser using this single line of code in .NET:



System.Diagnostics.Process.Start( _ "http://cgi.sandbox.ebay.com/ws/" & "eBayISAPI.dll?ViewItem&item=" & CurrenteBayItemID)

Note that this URL works for items you've listed in the development sandbox; you'll need to change this URL for the production eBay.com site.

So that's basically it. The sample project accesses and lists the current items in the inventory database, lets users move items from that inventory list to eBay, and lets them retrieve status updates on the listed items. The user interface is simple and efficient so that users need only click a few times to make the magic happen.

This article only covered two of the fifty or so calls in eBay's API repertoire, but these are two of the most important. Having mastered these, you won't have any trouble with the others. I hope that seeing these in action will give you a sense of how easy it is to integrate your business with eBay.



Jeffrey P. McManus is eBay's Senior Manager of Developer Relations. He is the author and co-author of six books on software development, including the recent Database Access with Visual Basic .NET (with Jackie Goldstein) and The C# Developers Guide to ASP .NET, XML and ADO .NET (with Chris Kinsman). Reach him by email here.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date