News Search API - v7
The News API lets partners send a search query to Bing and get back a list of relevant news articles. Note you should call the News API if you need news content only. If you need other content such as images and webpages in addition to images, you must call the Search API which includes news articles in the response. You must display the news articles in the order provided in the response.
News Search
Get news articles relevant for a given query.
Select the testing console in the region where you created your resource:
Open API testing consoleRequest URL
Request parameters
The user's search query string
The number of news results to return in the response. The actual number delivered may be less than requested.
The zero-based offset that indicates the number of news 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": "News",
"instrumentation": {
"pingUrlBase": "https://www.bingapis.com/api/ping?IG=8EAC3740311E4593BF35765B236F47AC&CID=070910FF0C0362112C11188E0DD06323&ID=",
"pageLoadPingUrl": "https://www.bingapis.com/api/ping/pageload"
},
"readLink": "https://www.bing.com/api/V7/news/search?q=microsoft",
"totalEstimatedMatches": 1170000,
"value": [
{
"name": "Samsung Galaxy TabPro S First impressions: A serious competitor to Microsoft’s Surface lineup",
"url": "http://tech.firstpost.com/news-analysis/samsung-galaxy-tabpro-s-first-impressions-a-serious-competitor-to-microsofts-surface-lineup-297978.html/",
"urlPingSuffix": "DevEx,5020.1",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.25CDFDFD52AF92BA58B567A1EEFDDC45&pid=News",
"width": 700,
"height": 393
}
},
"description": "We’ve seen a few tablets running Windows 10 announced in the past, but this one is sure to draw all the attention. Firstly, it is Samsung and Microsoft, rivals otherwise, coming together to show the best of both sides. A good looking hybrid with ...",
"about": [
{
"readLink": "https://www.bing.com/api/V7/entities/cfb4265c-a085-f5ab-f132-74c3ca86d376",
"name": "Samsung Galaxy"
},
{
"readLink": "https://www.bing.com/api/V7/entities/a093e9b9-90f5-a3d5-c4b8-5855e1b01f85",
"name": "Microsoft"
},
{
"readLink": "https://www.bing.com/api/V7/entities/46f1ab09-6fd7-5f05-6e27-3a1aeb6cae45",
"name": "Impression"
}
],
"provider": [
{
"_type": "Organization",
"name": "Tech2"
}
],
"datePublished": "2016-02-05T07:01:00",
"category": "ScienceAndTechnology"
},
{
"name": "Microsoft Releases Windows 10 Mobile Build 10586.71 to All Testers",
"url": "http://news.softpedia.com/news/microsoft-releases-windows-10-mobile-build-10586-71-to-all-testers-499959.shtml",
"urlPingSuffix": "DevEx,5022.1",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.5AD6B7BC824F5A8E6F6ED5B7DA1C906E&pid=News",
"width": 700,
"height": 452
}
},
"description": "The Windows 10 Mobile development process seems to advance pretty nicely, with Microsoft deciding to roll out the most recent build to members of the slow ring too. Basically, builds are pushed to the slow ring only when the Windows development team ...",
"about": [
{
"readLink": "https://www.bing.com/api/V7/entities/16aeb6d9-9098-0a40-4970-8e46a4fcee12",
"name": "Microsoft Windows"
},
{
"readLink": "https://www.bing.com/api/V7/entities/a093e9b9-90f5-a3d5-c4b8-5855e1b01f85",
"name": "Microsoft"
},
{
"readLink": "https://www.bing.com/api/V7/entities/fd31547a-9016-4940-b644-78988670c18a",
"name": "Build"
}
],
"provider": [
{
"_type": "Organization",
"name": "Softpedia News"
}
],
"datePublished": "2016-02-05T05:35:00",
"category": "ScienceAndTechnology"
}
]
}
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://*.cognitiveservices.azure.com/bing/v7.0/news/search?q=microsoft&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"] = "microsoft";
queryString["count"] = "10";
queryString["offset"] = "0";
queryString["mkt"] = "en-us";
queryString["safeSearch"] = "Moderate";
var uri = "https://*.cognitiveservices.azure.com/bing/v7.0/news/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://*.cognitiveservices.azure.com/bing/v7.0/news/search");
builder.setParameter("q", "microsoft");
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": "microsoft",
"count": "10",
"offset": "0",
"mkt": "en-us",
"safeSearch": "Moderate",
};
$.ajax({
url: "https://*.cognitiveservices.azure.com/bing/v7.0/news/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://*.cognitiveservices.azure.com/bing/v7.0/news/search";
NSArray* array = @[
// Request parameters
@"entities=true",
@"q=microsoft",
@"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://*.cognitiveservices.azure.com/bing/v7.0/news/search');
$url = $request->getUrl();
$headers = array(
// Request headers
'Ocp-Apim-Subscription-Key' => '{subscription key}',
);
$request->setHeader($headers);
$parameters = array(
// Request parameters
'q' => 'microsoft',
'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': 'microsoft',
'count': '10',
'offset': '0',
'mkt': 'en-us',
'safeSearch': 'Moderate',
})
try:
conn = httplib.HTTPSConnection('*.cognitiveservices.azure.com')
conn.request("GET", "/bing/v7.0/news/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': 'microsoft',
'count': '10',
'offset': '0',
'mkt': 'en-us',
'safeSearch': 'Moderate',
})
try:
conn = http.client.HTTPSConnection('*.cognitiveservices.azure.com')
conn.request("GET", "/bing/v7.0/news/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://*.cognitiveservices.azure.com/bing/v7.0/news/search')
uri.query = URI.encode_www_form({
# Request parameters
'q' => 'microsoft',
'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