Developer

Seamlessly integrate applications with eBay using its Windows SDK

The eBay Windows SDK allows you to easily access eBay data within your application. Tony Patton gives you an overview of the functionality provided by the eBay Web services API.

 

The evolution of the Web from a marketing venue to an application platform opens up possibilities for developers. For instance, you may extend an application by taking advantage of Web service APIs offered by sites such as Amazon, Google, and eBay.

I was able to test the usefulness of this option recently when a project called for pulling data from eBay and other services. Here's a look at how you can work with eBay via its Windows SDK.

eBay's Web service API

eBay provides an easy-to-use Web interface for using its various services. The eBay Web service API allows you to communicate directly with the eBay database via XML. This lets you provide a custom interface or integrate eBay data and functionality in your application.

eBay also offers various SDKs to access the API using your preferred development language. SDKs currently exist for Windows, Java, Flash, JavaScript, PHP, and REST developers. You can check the eBay Developer Centers site for updates including new SDKs.

The Windows SDK simplifies working with the eBay API, as you don't have to work directly with the XML. In this article, I focus on the Windows SDK, which targets C#, .NET, ASP, and Visual Basic developers.

Windows SDK

The Windows SDK is available as a free download. It allows you to use one of the many APIs for interacting with eBay.

  • Shopping API: This entry-level API provides access to items on eBay. It also allows you to easily search for and browse items.
  • Trading API: This API provides access to private eBay data; that is, the listed items on the site may use it to manage their listings as well as purchase items.
  • Merchandising API: This API provides data for affiliates. This includes item and product recommendations that may be used for cross-selling and/or up-selling.
  • Client Alerts API: This API allows you to receive near real-time notifications (seller and buyer) regarding events on eBay.
  • Platform Notifications API: This API allows sellers or buyers to stay abreast of any events that happen with their items or account.
  • Research API: This API allows you to work with historical eBay data.

The key to properly being successful with the Windows SDK is knowing which API to use for your situation. For example, if you want to provide the ability to search eBay from your site, go with the Shopping API; if you need to access inventory data for an account, the Trading API is the way to go. Once you download and install the SDK, you're almost ready to put it use, but you first have to register with eBay.

Registration and working environments

The eBay site registration process collects personal information, including a user id and password, to access the site. Once you register, you may generate keys from your account page; these keys are required to access eBay. The keys include a development id, an application id, and a certificate id. In addition, you will need a user token, which you can generate from your account page.

There are two environments for working with the eBay API: sandbox and production. The sandbox allows you to test code, and it mirrors production in functionality, but production data is not accessed. There is a set of keys and a token for each environment. Once the keys and token are generated, you may associate them with an eBay account. This provides access to private data such as account settings or inventory data. A good example of accessing private data is working with inventory via the Trading API.

Environment setup

The installation of the Windows SDK includes DLL files for using eBay functionality. These files must be referenced by your .NET code to communicate with eBay. The main file is eBay.Service.dll; it provides access to all basic functionality. Once the reference is added in Visual Studio, you can include a using statement in your class or type the complete name of the class (as I do in the examples below).

In action

Once you have the necessary credentials for accessing eBay, you can easily test for proper functioning using the GeteBayOfficialTimeCall class; it provides various methods for retrieving the current date and time on the eBay server. The following example demonstrates its use and sets up an ApiContext object.

The ApiContext object in the eBay.Service.Core.Sdk namespace contains the credentials for accessing eBay; this includes the developer id, application id, certificate id, and user token generated for your account. Also, you specify the URL for the eBay API -- this allows you to easily work with the sandbox and then move it to production by changing the address.

In addition, the code uses the ApiLogManager class in the eBay.Service.Core.Sdk namespace; this allows you to log data according to interactions with the API. The API version is set since there have been multiple versions of the SDK released; it is set on the ApiContext object.

eBay.Service.Core.Sdk.ApiContext context = new eBay.Service.Core.Sdk.ApiContext();

context.ApiCredential.ApiAccount.Developer = "00000000-0000-0000-0000-000000000000";

context.ApiCredential.ApiAccount.Application = "Test-0000-0000-0000-000000000000";

context.ApiCredential.ApiAccount.Certificate = "00000000-0000-0000-0000-000000000000";

context.ApiCredential.eBayToken = "longstring";

context.SoapApiServerUrl = "https://api.sandbox.ebay.com/wsapi";

context.ApiLogManager = new eBay.Service.Core.Sdk.ApiLogManager();

context.ApiLogManager.ApiLoggerList.Add(new eBay.Service.Util.FileLogger("ebay.log", true, true, true));

context.ApiLogManager.EnableLogging = true;

context.Version = "511";

eBay.Service.Call.GeteBayOfficialTimeCall eBayTime = new eBay.Service.Call.GeteBayOfficialTimeCall(context);

DateTime eBayDT = eBayTime.GeteBayOfficialTime();

Console.WriteLine(eBayDT.ToLongDateString() + " - " + eBayDT.ToLongTimeString());

The code makes the call to the GeteBayOfficialTime method of the GeteBayOfficialTimeCall class with the ApiContext object passed in as its credentials to access the site. From that point, a DateTime object is populated with the date and time from eBay with the results displayed on the command line.

You can broaden your interaction with eBay to facilitate a search of the eBay database. The next example uses the GetSearchResultsCall class found in the eBay.Service.Call namespace to search eBay using keywords. The detail level of the search results (DetailLevelCodeType object) is set to ReturnAll, which means all attributes are returned. It is advised to avoid this setting when working with large amount of inventory since it substantially increases the data returned.

The results of the search are returned in a SearchResultItemTypeCollection object (found in the eBay.Service.Core.Soap namespace). This collection is traversed with the title of each matching item displayed on the command line.

eBay.Service.Core.Sdk.ApiContext context = new eBay.Service.Core.Sdk.ApiContext();

context.ApiCredential.ApiAccount.Developer = "00000000-0000-0000-0000-000000000000";

context.ApiCredential.ApiAccount.Application = "Test-0000-0000-0000-000000000000";

context.ApiCredential.ApiAccount.Certificate = "00000000-0000-0000-0000-000000000000";

context.ApiCredential.eBayToken = "longstring";

context.SoapApiServerUrl = "https://api.sandbox.ebay.com/wsapi";

context.ApiLogManager = new eBay.Service.Core.Sdk.ApiLogManager();

context.ApiLogManager.ApiLoggerList.Add(new eBay.Service.Util.FileLogger("ebay.log", true, true, true));

context.ApiLogManager.EnableLogging = true;

context.Version = "511";

eBay.Service.Call.GetSearchResultsCall srch = new GetSearchResultsCall(context);

srch.DetailLevelList.Add(eBay.Service.Core.Soap.DetailLevelCodeType.ReturnAll);

eBay.Service.Core.Soap.SearchResultItemTypeCollection coll = srch.GetSearchResults("Microsoft .NET");

for (int i=0; i < coll.Count; i++){

eBay.Service.Core.Soap.SearchResultItemType item = (eBay.Service.Core.Soap.SearchResultItemType)coll.ItemAt(i);

Console.WriteLine("Title: " + item.Item.Title);

}

eBay.Service.Call.GeteBayOfficialTimeCall eBayTime = new eBay.Service.Call.GeteBayOfficialTimeCall(GetContext());

The previous two examples show the Shopping API in use. The next example uses the Trading API to retrieve all products in the seller's inventory. The items returned are for the eBay user associated with the credentials used to access the API.

The GetSellerListCall object found in the eBay.Service.Call namespace is used. This object needs a start and end date, which are populated via the TimeFilter class found in the eBay.Service.Core.Soap namespace. The detail level of the data to return is set to return the description (DetailLevelCodeType.ItemReturnDescription). Pagination is used to loop through the inventory items (the API allows no more than 200 items per page).

A while loop is used to traverse results. The Execute method of the GetSellerListCall object is used to send the command to eBay. The description for each item is displayed on the command line. The page number is increased to get the next page, and the Execute method is called again. The while loop uses the HasMoreItems property of the GetSellerListCall object to signal when processing should halt.

eBay.Service.Core.Sdk.ApiContext context = new eBay.Service.Core.Sdk.ApiContext();

context.ApiCredential.ApiAccount.Developer = "00000000-0000-0000-0000-000000000000";

context.ApiCredential.ApiAccount.Application = "Test-0000-0000-0000-000000000000";

context.ApiCredential.ApiAccount.Certificate = "00000000-0000-0000-0000-000000000000";

context.ApiCredential.eBayToken = "longstring";

context.SoapApiServerUrl = "https://api.sandbox.ebay.com/wsapi";

context.ApiLogManager = new eBay.Service.Core.Sdk.ApiLogManager();

context.ApiLogManager.ApiLoggerList.Add(new eBay.Service.Util.FileLogger("ebay.log", true, true, true));

context.ApiLogManager.EnableLogging = true;

context.Version = "511";
eBay.Service.Call.GetSellerListCall apicall = new eBay.Service.Call.GetSellerListCall(context);

eBay.Service.Core.Soap.TimeFilter tf = new eBay.Service.Core.Soap.TimeFilter();

tf.TimeFrom = new DateTime(1900, 1, 1);

tf.TimeTo = DateTime.Now.AddDays(30);
apicall.EndTimeFilter = tf;

eBay.Service.Core.Soap.DetailLevelCodeTypeCollection dnctc = new eBay.Service.Core.Soap.DetailLevelCodeTypeCollection();

dnctc.Add(eBay.Service.Core.Soap.DetailLevelCodeType.ItemReturnDescription);

apicall.DetailLevelList = dnctc;

apicall.Pagination = new eBay.Service.Core.Soap.PaginationType();

apicall.Pagination.EntriesPerPage = 200;

apicall.Pagination.PageNumber = 1;

apicall.Execute();

int pagenumber = 1;

while (apicall.HasMoreItems) {

foreach (ItemType item in apicall.ItemList) {

if (!(item.Description == null)) {
Console.WriteLine(item.Description);

}

pagenumber += 1;

apicall.Pagination.PageNumber = pagenumber;

apicall.Execute();

These examples demonstrate some of the basic things you can do with the eBay Web service API. I found the amount of information on eBay regarding the API a bit overwhelming. The eBay Developer Forums is helpful for finding answers, but there is a lot of outdated information since there have been many iterations of the API.

A new world

The services provided by a site like eBay proves the assertion that the Web is now the platform. The eBay Windows SDK allows you to easily access eBay data within your .NET application. This article only scratches the surface of the functionality provided by the eBay API, but it provides a good starting point if you want to learn more.

Are you taking advantage of the eBay API, or the APIs of other sites, in your applications? Share your experience with the Web Developer community.

Tony Patton began his professional career as an application developer earning Java, VB, Lotus, and XML certifications to bolster his knowledge.

---------------------------------------------------------------------------------------

Get weekly development tips in your inbox Keep your developer skills sharp by signing up for TechRepublic's free Web Developer newsletter, delivered each Tuesday. Automatically subscribe today!

About

Tony Patton has worn many hats over his 15+ years in the IT industry while witnessing many technologies come and go. He currently focuses on .NET and Web Development while trying to grasp the many facets of supporting such technologies in a productio...

7 comments
codelavie
codelavie

great article ! and it's true that the web is now the platform. from a developer view i think the point is not "whether or not" to integrate with eBay, it is in most cases decided by customers, internal and external, the point for us is HOW. And it is quite challenge for us to have to learn new api/sdk each time we intergrate with something else on web.

The Admiral
The Admiral

Unfortunately eBay is no longer relevant when it comes to e-Commerce. They have ticked off the sellers, and the buyers are running from the site because of the fraud perpetrated with the eBay/PayPal combination where customers get no service from those companies, not the seller.

Justin James
Justin James

If your app has something to do with buying or selling products, have you looked at integrating it with eBay? Why or why not? J.Ja

herlizness
herlizness

> really? can you call a company with $35B market cap, no debt, $8B in annual revenues and 24% Qtrly revenue growth YOY irrelevant? You may not like the company, but I think it's fair to say that it's "relevant"

Justin James
Justin James

I've been hearing the "eBay has done some bad things to the sellers and we're never coming back!" song every few years since they first opened up. They're still going strong. I am sure that when they make unpopular changes, they *do* lose a fews sellers. The fact is, those sellers don't have many options, as long as ebay's changes don't alienate the *buyers*. :) They are also smart enough to reverse decisions that I truly unpopular when it seems like a good idea to do so. J.Ja

Justin James
Justin James

I've been an eBay user for so long, my ID doesn't have any numbers in it, and it really just my name. eBay used to be a giant yard sale more or less, and you could get some truly stunning deals. Now, eBay is *mostly* professional sellers, people who are using it as a replacement for a Web site of their own, and prices are all too often very close to retail because of it. On top of that, there seems to be at *least* one bidder on any given auction who does not know the true retail value of the item, and who bids up past that point. I agree, eBay is no longer a great place to buy stuff. It is still a very useful place to go, sometimes I get a great deal there, and using it is easy enough that I still start many purchasing trips there (especially for older items that I might catch at a clearance price), but I know longer use it nearly exclusively like I did 10 years ago either. J.Ja

herlizness
herlizness

I'll stand by my position on EBAY but I have noticed over time that there seem to be fewer and fewer "truly good deals" on EBAY from a buyer's perspective; a lot of things I can pick up locally at about the same price and with less risk ... doesn't mean I don't use the service anymore -- and I did recently save about 50% on an item -- but I think they need to keep a close eye on what level of cost sellers have to pass through.

Editor's Picks