Blog

Where we discuss our work, thoughts, and process

Search Microsoft Bing with XML and JSON APIs

Bing! Opportunity is ringing.

Bing Search Engine interface

Microsoft recently released Bing!, a re-branded and much improved search engine based on its older and less successful Live Search platform. Bing! quickly gathered a small share of the search market after its initial release, placing it just behind Yahoo! but still far behind the Google powerhouse.

Today, however, the game has changed. According to the New York Times, Microsoft and Yahoo! announced a deal on a search and advertising partnership that will give Bing! approximately 28% share of the search market. Microsoft Bing! will provide the search technologies to power Yahoo!'s media websites. Meanwhile, Yahoo! forgoes its own search initiatives to strengthen itself as a media producer. Ultimately, this deal will bring more ad revenue to Yahoo! (88% of search-generated ad revenue, initially) while driving more search traffic to Microsoft's Bing! search engine.

Exploring Bing's search APIs

That said, today is an exciting time to be a web developer. Although the fate of several innovative Yahoo! search tools like B.O.S.S and social site Del.icio.us fall into question, there are new and exciting search APIs to discover with Bing!.

Bing!'s search API can provide search results programmatically as XML or JSON. Search results are fetched from various sources, including the Web, Images, News, Encarta Online, Phonebook, RelatedSearch, and Advertisements.

Get a Bing! Application ID

Before you can query Bing!'s search APIs, you must first obtain an Application ID from the Bing! Developer Center. Click on "Create an AppID" beneath "Get Started" and follow the instructions on the website.

Bing! Search API using XML

It is very simple to query Bing! programatically for XML search results. You only need to submit an HTTP GET request to the correct URL using several GET parameters (in other words, paste the URL below into a web browser and insert your application id). For example, we can search Bing! for "web design" by sending the following HTTP GET query.

http://api.search.live.net/xml.aspx?Appid=[your_app_id]&query=web+design&sources=web

Let's break this down. First, we are sending this GET request to http://api.search.live.net/xml.aspx. This URL will return search results as XML (indicated by the "xml.aspx" URI suffix). Next, we append our unique application ID as the "Appid" parameter; this is the Application ID you obtained from the Bing! Developer Center above. Next, we tell Bing! what we want to find; we append the "query" parameter and set its value to our search term "web+design". Last, we tell Bing! where to search; in this example we will search Bing!'s Web search index. Other search sources include "instantanswer", "spell", "phonebook", "relatedsearch", "news", and "ad".

The search results for the above query are returned as XML and look like this (shortened for brevity):

<?xml version="1.0" encoding="utf-8" ?>
<?pageview_candidate?>
<SearchResponse xmlns="http://schemas.microsoft.com/LiveSearch/2008/04/XML/element" Version="2.2">
	<Query>
		<SearchTerms>web design</SearchTerms>
	</Query>
	<web:Web xmlns:web="http://schemas.microsoft.com/LiveSearch/2008/04/XML/web">
		<web:Total>838000000</web:Total>
		<web:Offset>0</web:Offset>
		<web:Results>
			<web:WebResult>
				<web:Title>Open Source Web Design - Download free web design templates.</web:Title>
				<web:Description>
					Download and upload free web designs. ... We love design. Open Source Web Design is 
					a site to download free web design templates and share yours with others.
				</web:Description>
				<web:Url>http://www.oswd.org/</web:Url>
				<web:CacheUrl>http://cc.bingj.com/cache.aspx?q=web+design&amp;d=76473009964269&amp;w=e02b083,2fc32d54</web:CacheUrl>
				<web:DisplayUrl>www.oswd.org</web:DisplayUrl>
				<web:DateTime>2009-07-28T01:23:23Z</web:DateTime>
			</web:WebResult>
			<web:WebResult>
				<web:Title>Web design - Wikipedia, the free encyclopedia</web:Title>
				<web:Description>
					Web design is the skill of creating presentations of content (usually hypertext or hypermedia) 
					that is delivered to an end-user through the World Wide Web, by way of a Web browser ...
				</web:Description>
				<web:Url>http://en.wikipedia.org/wiki/Web_design</web:Url>
				<web:CacheUrl>http://cc.bingj.com/cache.aspx?q=web+design&amp;d=76462368293664&amp;w=85f192a,196c3e85</web:CacheUrl>
				<web:DisplayUrl>en.wikipedia.org/wiki/Web_design</web:DisplayUrl>
				<web:DateTime>2009-07-27T01:17:25Z</web:DateTime>
			</web:WebResult>
		</web:Results>
	</web:Web>
</SearchResponse>

Bing! Search API using JSON

Javascript developers will be excited to learn that Bing! can also return search results as JSON, or Javascript Object Notation. The same ideas above still apply here. We submit an HTTP GET request with the "Appid", "query", and "sources" GET parameters. However, the base URL is different. We can search Bing! for "web design" using the JSON interface with this GET request:

http://api.search.live.net/json.aspx?Appid=[your_app_id]&query=web+design&sources=web

The search results for this query are returned as JSON and look like this:

{"SearchResponse":
	{
		"Version":"2.2",
		"Query":{"SearchTerms":"web design"},
		"Web":{
			"Total":838000000,
			"Offset":0,
			"Results":[
				{
					"Title":"Open Source Web Design - Download free web design templates.",
					"Description":"Download and upload free web designs. ...",
					"Url":"http://www.oswd.org/",
					"CacheUrl":"http://cc.bingj.com/cache.aspx?q=web+design&d=76473009964269&w=e02b083,2fc32d54",
					"DisplayUrl":"www.oswd.org",
					"DateTime":"2009-07-28T01:23:23Z"
				},
				{
					"Title":"Web design - Wikipedia, the free encyclopedia",
					"Description":"Web design is the skill of creating presentations...",
					"Url":"http://en.wikipedia.org/wiki/Web_design",
					"CacheUrl":"http://cc.bingj.com/cache.aspx?q=web+design&d=76462368293664&w=85f192a,196c3e85",
					"DisplayUrl":"en.wikipedia.org/wiki/Web_design",
					"DateTime":"2009-07-27T01:17:25Z"
				}
			]
		}
	}
}

Monetizing your search results

Microsoft is currently running an Ads Pilot Program. This program allows you to receive compensation for ads placed in your website's search results. To incorporate ads on your website, you must first obtain an Application ID from the Bing! Developer Center. Next, you must submit an Ads Pilot Program application. After you are contacted by a Microsoft representative and get setup, you can append "ad" to your search query's sources parameter. This pilot program is still very much in development. You can read more about it at the Bing! Developer Center Help website.

Comments

AJ's avatar
AJ

Josh - Do you know if the "phonebook" feature within the search API actually means a full national business database, complete with business names, phone numbers, address info, SIC codes, etc?

Josh Lockhart 's avatar
Josh Lockhart

@AJ The details about the phonebook search source are scare, but I can point you to the official Microsoft documentation on it.

http://msdn.microsoft.com/en-us/library/dd251005.aspx

It appears to be more like Google Local where you can search businesses based on certain criteria and receive search results that include the business phone number, address, website, and user ratings.

tratamento de rugas com luz pulsada's avatar
tratamento de rugas com luz pulsada
WS

Leave a comment