Using Web Services in your Gadget

Alan Lewis – eBay Technical Evangelist



eBay Inc. confidential

I lost my voice earlier this morning


eBay Inc. confidential



eBay Inc. confidential

I have some cool stuff to show you though
5 eBay Inc. confidential



eBay Inc. confidential

So, I’ll give it a try
eBay Inc. confidential


Here goes…


eBay Inc. confidential

Huh? What’s this presentation about???

• Web Services

– – – –

You may have heard of them Yes, they are actually useful No, you don’t have to use SOAP Lots of services are out there for you to use (finally)

• Gadgets – Or Widgets – Or Plugins

– Or Panels – Definition: “mini-applications that let you perform common tasks and provide you with fast access to information” – Translation: They do cool stuff


eBay Inc. confidential

Why Should I Care?

• Gadgets are cool

• Web services offer lots of reusable data and functionality
• MIXing them up (nice plug) in your gadget saves you headaches • Alternative to doing it this way – server side coding

– Need to scale your server to handle traffic from gadget – Different skill set required – Eww!!!


eBay Inc. confidential

So, what sorts of web services are out there?

• I’m so glad you asked… here is a totally random example:

eBay Web Services!!!

• Please permit me a short detour to summarize


eBay Inc. confidential

eBay Web Service Features

• Search

• Listing Items
• Transaction/Order Management • My eBay • eBay Stores • Feedback Management • Watch List • Bidding (with signed agreement) • In short, almost everything you can do on the site


eBay Inc. confidential

Different Flavors of eBay Web Services


– Both support the same feature set (all calls) – Calls go over HTTPS

– supports GetSearchResults call


eBay Inc. confidential

Sample Call Request
XML API: <?xml version="1.0" encoding="utf-8"?> <GetSearchResultsRequest xmlns="urn:ebay:apis:eBLBaseComponents"> <RequesterCredentials> <eBayAuthToken>ABC123</eBayAuthToken> </RequesterCredentials> <Query>iPod Nano</Query> </GetSearchResultsRequest>

REST API 123=&RequestUserId=alanlewis0&Query=iPod%20Nano&Schema=1


eBay Inc. confidential

Sample Call Response

XML API and REST API (same response)

<?xml version="1.0" encoding="utf-8"?>
<GetSearchResultsRequest xmlns="urn:ebay:apis:eBLBaseComponents"> … <Item> <ItemID>4036874357</ItemID> … <SellingStatus> <BidCount>31</BidCount> <CurrentPrice currencyID="USD">80.0</CurrentPrice>

<Site>US</Site> <Title>Used Apple iPod Nano MP3 Player Good Condition</Title> …

… </GetSearchResultsRequest>
15 eBay Inc. confidential

And Now…

16 eBay Inc. confidential

• Supports RSS feeds and Gadgets

• Gadgets are implemented in javascript + CSS
• Still alpha feel – emerging feature set and very buggy at times (especially with CSS support)


eBay Inc. confidential

Design Philosophy

• Gadgets call for a fresh design approach

• Sort of like code for mobile devices
– Limited screen real-estate – Limited functionality/APIs

• Except not
– Still coding for the browser– multiple windows/tabs, cross-browser issues – Asynchronous interaction, more bandwidth


eBay Inc. confidential

Challenge 1: Security Restrictions

• Calls can’t go across domains
– If the gadget was served up from, can’t call

• solution to this: proxy!
– Supports XML data (except XHTML) and RSS feeds – Currently only supports HTTP GET (contrary to docs – support for POST will be added in the future) – Can’t proxy HTTPS yet, so only option for eBay is REST API
var r = Web.Network.createRequest(

Web.Network.Type.XML, searchQuery, {proxy:"generic"}, eBaySearchCallback);


eBay Inc. confidential

Challenge 2: Namespaces

• IE javascript engine can’t handle XML data in default namespaces • Solution: Use ugly RegEx hack to remove namespace:
var rootText = response.responseText; var re = /xmlns="urn:ebay:apis:eBLBaseComponents"/g; rootText = rootText.replace(re, ""); var responseWithoutNamespaces; if (window.ActiveXObject) { responseWithoutNamespaces = new ActiveXObject("Microsoft.XMLDOM"); responseWithoutNamespaces.async="false"; responseWithoutNamespaces.loadXML(rootText); } else { responseWithoutNamespaces = document.implementation.createDocument("","",null); responseWithoutNamespaces.loadXML(rootText); }


eBay Inc. confidential

And now…


• The gadget is open sourced
• Commercial software-friendly open source license: CDDL • Yeah!

• Lets go check it out…


eBay Inc. confidential

Now More Code

• Here is the code, in-depth


eBay Inc. confidential

Other Web Services

• Lots to choose from:

• REST is very popular, but has limitations
• RSS feeds are web services too


eBay Inc. confidential

Building Commercial Apps

• One issue to keep in mind is many Web services out there force noncommercial use • Shameless plug: that’s not the case with eBay Web services • One way to make money with your Gadget is to use an affiliate program like eBay’s:


eBay Inc. confidential

Other Gadget/Widget Platforms

• Vista Sidebar

– Bundled with Vista, but limited capabilities (thusfar)
• Yahoo! Widget Engine (Konfabulator) – Multi-platform support, integration with Desktop still clumsy • Apple Dashboard – Best desktop integration, but only for OSX • Google Desktop – (Sidebar) – Information-rich widgets, but harder to build, bundled with a product IT departments hate • Google Personalized Home Page – Sorta like – less functionality but better visibility


eBay Inc. confidential

Learn More Stuff
• More on eBay Web Services: Its totally free!

• eBay Developers Conference, baby! June 10-12, Mandalay Bay, Las Vegas
• eBay Gadget available in the Gallery: • Open sourced at: • Sanaz Ahari’s presentation immediately following this one, in C/D


eBay Inc. confidential