Web Search API - v7
The Search API provides a similar (but not exact) experience to Bing.com/Search by returning search results that Bing determines are relevant to the specified query. The results also identify the order that you must display the content in (see Using Ranking to Display Results). The response may also include related search links and suggest a query string that may more accurately represent the user's intent. Typically, you will call this API instead of calling the other APIs in the Bing API family, such as the Image API or News API.
Search
Get web, image, news, & videos results for a given query.
Select the testing console in the region where you created your resource:
Global West US West US 2 East US East US 2 West Central US South Central US West Europe North Europe Southeast Asia East Asia Australia East Brazil South Canada Central Central India UK South Japan East Central US France Central Korea Central Japan West North Central US South Africa NorthRequest URL
Request parameters
The user's search query string
The number of search results to return in the response. The actual number delivered may be less than requested.
The zero-based offset that indicates the number of search results to skip before returning results.
The market where the results come from. Typically, this is the country where the user is making the request from; however, it could be a different country if the user is not located in a country where Bing delivers results. The market must be in the form -. For example, en-US.
Full list of supported markets:
es-AR,en-AU,de-AT,nl-BE,fr-BE,pt-BR,en-CA,fr-CA,es-CL,da-DK,fi-FI,fr-FR,de-DE,zh-HK,en-IN,en-ID,en-IE,it-IT,ja-JP,ko-KR,en-MY,es-MX,nl-NL,en-NZ,no-NO,zh-CN,pl-PL,pt-PT,en-PH,ru-RU,ar-SA,en-ZA,es-ES,sv-SE,fr-CH,de-CH,zh-TW,tr-TR,en-GB,en-US,es-US
A filter used to filter results for adult content.
Request headers
Request body
Response 200
{
"_type": "SearchResponse",
"instrumentation": {
"pingUrlBase": "https://www.bingapis.com/api/ping?IG=E86668D804C149438DFC0972CE52C9E3&CID=070910FF0C0362112C11188E0DD06323&ID=",
"pageLoadPingUrl": "https://www.bingapis.com/api/ping/pageload"
},
"webPages": {
"webSearchUrl": "https://www.bing.com/search?q=bill+gates",
"webSearchUrlPingSuffix": "DevEx,5425.1",
"totalEstimatedMatches": 14100000,
"value": [
{
"id": "https://www.bing.com/api/V7/#WebPages.0",
"name": "Bill & Melinda Gates Foundation - Official Site",
"url": "http://www.gatesfoundation.org/",
"urlPingSuffix": "DevEx,5081.1",
"about": [
{
"name": "Bill & Melinda Gates Foundation"
},
{
"name": "Bill Gates"
}
],
"displayUrl": "www.gatesfoundation.org",
"snippet": "The Gates Foundation’s effort to eradicate polio offers the chance to protect millions of children from paralysis forever.",
"deepLinks": [
{
"name": "Jobs",
"url": "http://www.gatesfoundation.org/jobs",
"urlPingSuffix": "DevEx,5071.1"
},
{
"name": "What We Do",
"url": "http://www.gatesfoundation.org/what-we-do",
"urlPingSuffix": "DevEx,5072.1"
},
{
"name": "Apply for a Grant",
"url": "http://www.gatesfoundation.org/how-we-work/resources/our-commitment-to-grantees",
"urlPingSuffix": "DevEx,5073.1"
},
{
"name": "Search Listings",
"url": "http://careers.gatesfoundation.org/",
"urlPingSuffix": "DevEx,5074.1"
},
{
"name": "How We Work",
"url": "http://www.gatesfoundation.org/how-we-work",
"urlPingSuffix": "DevEx,5075.1"
}
],
"dateLastCrawled": "2016-02-04T17:10:00"
},
{
"id": "https://www.bing.com/api/V7/#WebPages.1",
"name": "Bill Gates - Wikipedia, the free encyclopedia",
"url": "https://en.wikipedia.org/wiki/Bill_Gates",
"urlPingSuffix": "DevEx,5097.1",
"about": [
{
"name": "Bill Gates"
}
],
"displayUrl": "https://en.wikipedia.org/wiki/Bill_Gates",
"snippet": "William Henry \"Bill\" Gates III (born October 28, 1955) is an American business magnate, philanthropist, investor, and computer programmer. [2] [3] In 1975 ...",
"dateLastCrawled": "2016-02-05T03:09:00"
},
{
"id": "https://www.bing.com/api/V7/#WebPages.2",
"name": "Bill Gates - Official Site",
"url": "https://www.gatesnotes.com/",
"urlPingSuffix": "DevEx,5110.1",
"displayUrl": "https://www.gatesnotes.com",
"snippet": "Become a Gates Notes Insider Join the Gates Notes community to access exclusive content, comment on stories, subscribe to your favorite topics and more.",
"dateLastCrawled": "2016-02-03T18:50:00"
}
]
},
"images": {
"id": "https://www.bing.com/api/V7/#Images",
"readLink": "https://www.bing.com/api/V7/images/search?q=bill+gates&qpvt=bill+gates&qpvt=bill+gates",
"webSearchUrl": "https://www.bing.com/images/search?q=bill+gates&qpvt=bill+gates&qpvt=bill+gates",
"webSearchUrlPingSuffix": "DevEx,5025.1",
"isFamilyFriendly": true,
"value": [
{
"name": "Bill Gates Ranked Richest American by Forbes For 21st Straight Year",
"webSearchUrl": "https://www.bing.com/images/search?q=bill+gates&id=A204A8572C1640DE6830782F02A63C2E825D705A&FORM=IARRTH",
"webSearchUrlPingSuffix": "DevEx,5321.1",
"thumbnailUrl": "https://tse1.mm.bing.net/th?id=OIP.Me12187d95b2790e2644fdf18d5a30b3bH1&pid=Api",
"datePublished": "2014-09-29T21:50:00",
"contentUrl": "http://americanlivewire.com/wp-content/uploads/bill-gates1.jpg",
"hostPageUrl": "http://americanlivewire.com/2014-09-29-bill-gates-ranked-richest-american-forbes-21st-straight-year/",
"hostPageUrlPingSuffix": "DevEx,5445.1",
"contentSize": "1088572 B",
"encodingFormat": "jpeg",
"hostPageDisplayUrl": "http://americanlivewire.com/2014-09-29-bill-gates-ranked-richest-american-forbes-21st-straight-year/",
"width": 1588,
"height": 2393,
"thumbnail": {
"width": 318,
"height": 480
}
}
],
"displayShoppingSourcesBadges": false,
"displayRecipeSourcesBadges": true
},
"news": {
"id": "https://www.bing.com/api/V7/#News",
"readLink": "https://www.bing.com/api/V7/news/search?q=Bill+Gates",
"value": [
{
"name": "Bill Gates Doubles Down to Scale up Support for New Impact Investing Funds",
"url": "http://www.huffingtonpost.com/david-bank/bill-gates-doubles-down-t_b_9146778.html",
"urlPingSuffix": "DevEx,5175.1",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.94FE743052139FA7E51134C65616EDD4&pid=News",
"width": 570,
"height": 370
}
},
"description": "ImpactAlpha.com-- When Bill Gates agreed a couple years ago to put a small piece of his personal fortune into a fund that invests in companies serving low-income customers in India, he invited the fund managers to return with a plan to scale up their ...",
"about": [
{
"readLink": "https://www.bing.com/api/V7/entities/0d47c987-0042-5576-15e8-97af601614fa",
"name": "Bill Gates"
},
{
"readLink": "https://www.bing.com/api/V7/entities/b7fff496-7062-698c-2493-fa6871cd8c66",
"name": "Impact investing"
}
],
"provider": [
{
"_type": "Organization",
"name": "The Huffington Post"
}
],
"datePublished": "2016-02-04T22:56:00",
"category": "Business"
}
]
},
"relatedSearches": {
"id": "https://www.bing.com/api/V7/#RelatedSearches",
"value": [
{
"text": "Bill Gates Malaria",
"displayText": "Bill Gates Malaria",
"webSearchUrl": "https://www.bing.com/search?q=Bill+Gates+Malaria",
"webSearchUrlPingSuffix": "DevEx,5465.1"
},
{
"text": "Bill Gates Mansion",
"displayText": "Bill Gates Mansion",
"webSearchUrl": "https://www.bing.com/search?q=Bill+Gates+Mansion",
"webSearchUrlPingSuffix": "DevEx,5466.1"
}
]
},
"videos": {
"id": "https://www.bing.com/api/V7/#Videos",
"readLink": "https://www.bing.com/api/V7/videos/search?q=bill+gates",
"webSearchUrl": "https://www.bing.com/videos/search?q=bill+gates",
"webSearchUrlPingSuffix": "DevEx,5053.1",
"isFamilyFriendly": true,
"value": [
{
"name": "Bill Gates 2.0",
"description": "For Bill Gates, technology is still the solution. He shows Charlie Rose some inventions he's working on to help heal the world.",
"webSearchUrl": "https://www.bing.com/videos/search?q=bill%20gates#view=detail&mid=234E4D8C9DC6C5707C0E234E4D8C9DC6C5707C0E",
"webSearchUrlPingSuffix": "DevEx,5430.1",
"thumbnailUrl": "https://tse2.mm.bing.net/th?id=WN.qLvK%2bJin%2b21addnQ0lsxUw&pid=Api",
"datePublished": "2013-05-14T18:35:52",
"publisher": [
{
"name": "YouTube"
}
],
"contentUrl": "https://www.youtube.com/watch?v=cPy0nWYYCFg",
"hostPageUrl": "https://www.youtube.com/watch?v=cPy0nWYYCFg",
"hostPageUrlPingSuffix": "DevEx,5429.1",
"encodingFormat": "mp4",
"hostPageDisplayUrl": "https://www.youtube.com/watch?v=cPy0nWYYCFg",
"width": 1280,
"height": 720,
"duration": "PT13M42S",
"motionThumbnailUrl": "https://tse2.mm.bing.net/th?id=OM.DnxwxcadjE1OIw&pid=Api",
"embedHtml": "<iframe width=\"1280\" height=\"720\" src=\"http://www.youtube.com/embed/cPy0nWYYCFg?autoplay=1\" frameborder=\"0\" allowfullscreen></iframe>",
"allowHttpsEmbed": true,
"viewCount": 80292,
"thumbnail": {
"width": 300,
"height": 168
}
}
],
"scenario": "List"
}
}
Response 401
{
"error":{
"statusCode": 401,
"message": "Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key."
}
}
Response 403
{
"error":{
"statusCode": 403,
"message": "Out of call volume quota. Quota will be replenished in 2.12 days."
}
}
Response 429
{
"error":{
"statusCode": 429,
"message": "Rate limit is exceeded. Try again in 26 seconds."
}
}
Code samples
@ECHO OFF
curl -v -X GET "https://japanwest.api.cognitive.microsoft.com/bing/v7.0/search?q=bill gates&count=10&offset=0&mkt=en-us&safesearch=Moderate"
-H "Ocp-Apim-Subscription-Key: {subscription key}"
--data-ascii "{body}"
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;
namespace CSHttpClientSample
{
static class Program
{
static void Main()
{
MakeRequest();
Console.WriteLine("Hit ENTER to exit...");
Console.ReadLine();
}
static async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{subscription key}");
// Request parameters
queryString["q"] = "bill gates";
queryString["count"] = "10";
queryString["offset"] = "0";
queryString["mkt"] = "en-us";
queryString["safesearch"] = "Moderate";
var uri = "https://japanwest.api.cognitive.microsoft.com/bing/v7.0/search?" + queryString;
var response = await client.GetAsync(uri);
}
}
}
// // This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class JavaSample
{
public static void main(String[] args)
{
HttpClient httpclient = HttpClients.createDefault();
try
{
URIBuilder builder = new URIBuilder("https://japanwest.api.cognitive.microsoft.com/bing/v7.0/search");
builder.setParameter("q", "bill gates");
builder.setParameter("count", "10");
builder.setParameter("offset", "0");
builder.setParameter("mkt", "en-us");
builder.setParameter("safesearch", "Moderate");
URI uri = builder.build();
HttpGet request = new HttpGet(uri);
request.setHeader("Ocp-Apim-Subscription-Key", "{subscription key}");
// Request body
StringEntity reqEntity = new StringEntity("{body}");
request.setEntity(reqEntity);
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null)
{
System.out.println(EntityUtils.toString(entity));
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
var params = {
// Request parameters
"q": "bill gates",
"count": "10",
"offset": "0",
"mkt": "en-us",
"safesearch": "Moderate",
};
$.ajax({
url: "https://japanwest.api.cognitive.microsoft.com/bing/v7.0/search?" + $.param(params),
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","{subscription key}");
},
type: "GET",
// Request body
data: "{body}",
})
.done(function(data) {
alert("success");
})
.fail(function() {
alert("error");
});
});
</script>
</body>
</html>
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString* path = @"https://japanwest.api.cognitive.microsoft.com/bing/v7.0/search";
NSArray* array = @[
// Request parameters
@"entities=true",
@"q=bill gates",
@"count=10",
@"offset=0",
@"mkt=en-us",
@"safesearch=Moderate",
];
NSString* string = [array componentsJoinedByString:@"&"];
path = [path stringByAppendingFormat:@"?%@", string];
NSLog(@"%@", path);
NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
[_request setHTTPMethod:@"GET"];
// Request headers
[_request setValue:@"{subscription key}" forHTTPHeaderField:@"Ocp-Apim-Subscription-Key"];
// Request body
[_request setHTTPBody:[@"{body}" dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response = nil;
NSError *error = nil;
NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
if (nil != error)
{
NSLog(@"Error: %@", error);
}
else
{
NSError* error = nil;
NSMutableDictionary* json = nil;
NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
NSLog(@"%@", dataString);
if (nil != _connectionData)
{
json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
}
if (error || !json)
{
NSLog(@"Could not parse loaded json with error:%@", error);
}
NSLog(@"%@", json);
_connectionData = nil;
}
[pool drain];
return 0;
}
<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';
$request = new Http_Request2('https://japanwest.api.cognitive.microsoft.com/bing/v7.0/search');
$url = $request->getUrl();
$headers = array(
// Request headers
'Ocp-Apim-Subscription-Key' => '{subscription key}',
);
$request->setHeader($headers);
$parameters = array(
// Request parameters
'q' => 'bill gates',
'count' => '10',
'offset' => '0',
'mkt' => 'en-us',
'safesearch' => 'Moderate',
);
$url->setQueryVariables($parameters);
$request->setMethod(HTTP_Request2::METHOD_GET);
// Request body
$request->setBody("{body}");
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
########### Python 2.7 #############
import httplib, urllib, base64
headers = {
# Request headers
'Ocp-Apim-Subscription-Key': '{subscription key}',
}
params = urllib.urlencode({
# Request parameters
'q': 'bill gates',
'count': '10',
'offset': '0',
'mkt': 'en-us',
'safesearch': 'Moderate',
})
try:
conn = httplib.HTTPSConnection('japanwest.api.cognitive.microsoft.com')
conn.request("GET", "/bing/v7.0/search?%s" % params, "{body}", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64
headers = {
# Request headers
'Ocp-Apim-Subscription-Key': '{subscription key}',
}
params = urllib.parse.urlencode({
# Request parameters
'q': 'bill gates',
'count': '10',
'offset': '0',
'mkt': 'en-us',
'safesearch': 'Moderate',
})
try:
conn = http.client.HTTPSConnection('japanwest.api.cognitive.microsoft.com')
conn.request("GET", "/bing/v7.0/search?%s" % params, "{body}", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
require 'net/http'
uri = URI('https://japanwest.api.cognitive.microsoft.com/bing/v7.0/search')
uri.query = URI.encode_www_form({
# Request parameters
'q' => 'bill gates',
'count' => '10',
'offset' => '0',
'mkt' => 'en-us',
'safesearch' => 'Moderate'
})
request = Net::HTTP::Get.new(uri.request_uri)
# Request headers
request['Ocp-Apim-Subscription-Key'] = '{subscription key}'
# Request body
request.body = "{body}"
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
http.request(request)
end
puts response.body