Answer Search API

API change history

The Answer Search API returns entities, facts and web pages

Answer Search

Get entities, places, facts and webpages results for a given query.

Try it

Request

Request URL

Request parameters

  • string

    Query

  • string

    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 'language code-country code'. For example, en-US.



    Full list of supported markets:
    en-US
  • (optional)
    number

    The number of search results to return in the response. The actual number delivered may be less than requested.

  • (optional)
    number

    The zero-based offset that indicates the number of search results to skip before returning results.

  • (optional)
    string

    A filter used to filter results for adult content.

Request headers

  • string
    Subscription key which provides access to this API. Found in your Profile.

Request body

Responses

200 OK

Representations

{
  "_type": "SearchResponse",
  "queryContext": {
    "originalQuery": "Who is Satya"
  },
  "webPages": {
    "webSearchUrl": "https://www.bing.com/search?q=Who+is+Satya",
    "totalEstimatedMatches": 10200000,
    "value": [
      {
        "id": "https://www.bingapis.com/api/v7/#WebPages.0",
        "name": "Satya Nadella - Wikipedia",
        "url": "https://en.wikipedia.org/wiki/Satya_Nadella",
        "about": [
          {
            "name": "Satya Nadella"
          },
          {
            "name": "Satya Nadella"
          }
        ],
        "isFamilyFriendly": true,
        "displayUrl": "https://en.wikipedia.org/wiki/Satya_Nadella",
        "snippet": "Satya Narayana Nadella (born 19 August 1967) is an Indian American business executive. He is the current Chief Executive Officer (CEO) of Microsoft, succeeding Steve Ballmer in 2014.",
        "dateLastCrawled": "2018-03-30T02:00:00Z",
        "language": "en"
      },
      {
        "id": "https://www.bingapis.com/api/v7/#WebPages.1",
        "name": "Satya - Wikipedia",
        "url": "https://en.wikipedia.org/wiki/Satya",
        "about": [
          {
            "name": "Satya"
          }
        ],
        "isFamilyFriendly": true,
        "displayUrl": "https://en.wikipedia.org/wiki/Satya",
        "snippet": "Satya is the Sanskrit word for truth. It also refers to a virtue in Indian religions, referring to being truthful in one's thought, speech and action. In ...",
        "dateLastCrawled": "2018-03-29T21:50:00Z",
        "language": "en"
      },
      {
        "id": "https://www.bingapis.com/api/v7/#WebPages.2",
        "name": "Satya Nadella: The Man Who Is Transforming Microsoft",
        "url": "http://fortune.com/satya-nadella-microsoft-ceo/",
        "isFamilyFriendly": true,
        "displayUrl": "fortune.com/satya-nadella-microsoft-ceo",
        "snippet": "On the road with Microsoft's Satya Nadella on his traveling revival show.",
        "dateLastCrawled": "2018-03-29T19:42:00Z",
        "language": "en"
      },
      {
        "id": "https://www.bingapis.com/api/v7/#WebPages.3",
        "name": "Just who is Microsoft's Satya Nadella? - USA TODAY",
        "url": "https://www.usatoday.com/story/tech/personal/2014/02/04/just-who-is-microsofts-satya-nadella/5067221/",
        "about": [
          {
            "name": "Satya Nadella"
          }
        ],
        "isFamilyFriendly": true,
        "displayUrl": "https://www.usatoday.com/story/tech/personal/2014/02/04/just-who...",
        "snippet": "SAN FRANCISCO — Microsoft's search for the heir to CEO Steve Ballmer, a process that dragged for months and touched off the biggest parlor game in tech of Name That CEO, has finally come to and end with an insider selection. The software behemoth tapped Satya Nadella as CEO, elevated John Thompson ...",
        "dateLastCrawled": "2018-03-19T02:33:00Z",
        "language": "en"
      },
      {
        "id": "https://www.bingapis.com/api/v7/#WebPages.4",
        "name": "For Microsoft CEO Satya Nadella, business is personal ...",
        "url": "https://www.cbsnews.com/news/for-microsoft-ceo-satya-nadella-business-is-personal/",
        "about": [
          {
            "name": "Satya Nadella"
          }
        ],
        "isFamilyFriendly": true,
        "displayUrl": "https://www.cbsnews.com/news/for-microsoft-ceo-satya-nadella...",
        "snippet": "The head of the corporate giant says changing the company's culture was essential to meeting customers' needs, spurring innovation, and protecting its immigrant workers",
        "dateLastCrawled": "2018-03-31T14:06:00Z",
        "language": "en"
      },
      {
        "id": "https://www.bingapis.com/api/v7/#WebPages.5",
        "name": "Satya: A Practice of Truthfulness | Yoga International",
        "url": "https://yogainternational.com/article/view/satya-a-practice-of-truthfulness",
        "isFamilyFriendly": true,
        "displayUrl": "https://yogainternational.com/.../satya-a-practice-of-truthfulness",
        "snippet": "Satya (truthfulness), the second of the five yamas (restraints) described in the Yoga Sutra, guides us to think, speak, and act with integrity.",
        "dateLastCrawled": "2018-03-30T18:20:00Z",
        "language": "en"
      },
      {
        "id": "https://www.bingapis.com/api/v7/#WebPages.6",
        "name": "Who is Satya Nadella? - Quora",
        "url": "https://www.quora.com/Who-is-Satya-Nadella",
        "about": [
          {
            "name": "Satya Nadella"
          }
        ],
        "isFamilyFriendly": true,
        "displayUrl": "https://www.quora.com/Who-is-Satya-Nadella",
        "snippet": "Here’s 10 things to know about Microsoft’s new CEO, Satya Nadella. 1. He grew up in India. Nadella was born in 1967 in Hyderabad, India, attended public schools there and received a bachelors’ degree in electrical engineering from Manipal Univ...",
        "dateLastCrawled": "2018-03-30T12:48:00Z",
        "language": "en"
      },
      {
        "id": "https://www.bingapis.com/api/v7/#WebPages.7",
        "name": "Profile: Who is Satya Nadella - USA TODAY",
        "url": "https://www.usatoday.com/story/tech/2014/07/17/satya-nadella-profile/12775419/",
        "about": [
          {
            "name": "Satya Nadella"
          }
        ],
        "isFamilyFriendly": true,
        "displayUrl": "https://www.usatoday.com/story/tech/2014/07/17/satya-nadella...",
        "snippet": "When Satya Nadella was named Microsoft CEO in February, analysts who follow the company said one of his top priorities must be to mold the software behemoth in to a more nimble company.",
        "dateLastCrawled": "2018-03-11T12:24:00Z",
        "language": "en"
      },
      {
        "id": "https://www.bingapis.com/api/v7/#WebPages.8",
        "name": "Satya Nadella | Stories",
        "url": "https://news.microsoft.com/exec/satya-nadella/",
        "about": [
          {
            "name": "Satya Nadella"
          },
          {
            "name": "Satya Nadella"
          }
        ],
        "isFamilyFriendly": true,
        "displayUrl": "https://news.microsoft.com/exec/satya-nadella",
        "snippet": "Satya Nadella is Chief Executive Officer of Microsoft. Before being named CEO in February 2014, Nadella held leadership roles in both enterprise and consumer businesses across the company.",
        "dateLastCrawled": "2018-03-30T20:11:00Z",
        "language": "en"
      }
    ]
  },
  "entities": {
    "value": [
      {
        "id": "https://www.bingapis.com/api/v7/#Entities.0",
        "contractualRules": [
          {
            "_type": "ContractualRules/LicenseAttribution",
            "targetPropertyName": "description",
            "mustBeCloseToContent": true,
            "license": {
              "name": "CC-BY-SA",
              "url": "http://creativecommons.org/licenses/by-sa/3.0/"
            },
            "licenseNotice": "Text under CC-BY-SA license"
          },
          {
            "_type": "ContractualRules/LinkAttribution",
            "targetPropertyName": "description",
            "mustBeCloseToContent": true,
            "text": "Wikipedia",
            "url": "http://en.wikipedia.org/wiki/Satya"
          },
          {
            "_type": "ContractualRules/MediaAttribution",
            "targetPropertyName": "image",
            "mustBeCloseToContent": true,
            "url": "http://en.wikipedia.org/wiki/Satya"
          }
        ],
        "webSearchUrl": "https://www.bing.com/entityexplore?q=Satya&filters=sid:%22b575fdd3-fce3-fc52-d0f0-56b97e22f97e%22&elv=AXXfrEiqqD9r3GuelwApulothUcgA0QE*72g7lYU*qbd9iqic7I4TTwv3e*Pg969Ep59g31DcyKOEMLIWezBP*7hVCYSDs8DvSdKNWZE*bv9",
        "name": "Satya",
        "url": "https://en.m.wikipedia.org/wiki/Satya_(disambiguation)",
        "image": {
          "name": "Satya",
          "thumbnailUrl": "https://www.bing.com/th?id=Aca47f5a9237ef3e87d4bbc3f2b499862&w=50&h=50&c=7&rs=1&qlt=80&cdv=1&pid=16.1",
          "provider": [
            {
              "_type": "Organization",
              "url": "http://en.wikipedia.org/wiki/Satya"
            }
          ],
          "hostPageUrl": "http://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Belief_Venn_diagram.svg/500px-Belief_Venn_diagram.svg.png",
          "width": 75,
          "height": 75,
          "sourceWidth": 300,
          "sourceHeight": 191
        },
        "description": "Satya is the Sanskrit word for truth. It also refers to a virtue in Indian religions, referring to being truthful in one's thought, speech and action. In Yoga, satya is one of five yamas, the virtuous restraint from falsehood and distortion of reality in one's expressions and actions.",
        "entityPresentationInfo": {
          "entityScenario": "DisambiguationItem",
          "entityTypeHints": [
            "Generic"
          ]
        },
        "bingId": "b575fdd3-fce3-fc52-d0f0-56b97e22f97e"
      }
    ]
  },
  "facts": {
    "id": "https://www.bingapis.com/api/v7/#Facts",
    "contractualRules": [
      {
        "_type": "ContractualRules/LinkAttribution",
        "text": "en.wikipedia.org/wiki/Satya_Nadella",
        "url": "https://en.wikipedia.org/wiki/Satya_Nadella"
      }
    ],
    "attributions": [
      {
        "providerDisplayName": "en.wikipedia.org/wiki/Satya_Nadella",
        "seeMoreUrl": "https://en.wikipedia.org/wiki/Satya_Nadella"
      }
    ],
    "value": [
      {
        "description": "Satya Nadella. Satya Narayana Nadella (born 19 August 1967) is an Indian American business executive. He is the current Chief Executive Officer (CEO) of Microsoft. He was appointed as CEO on 4 February 2014, succeeding Steve Ballmer.",
        "subjectName": "Who Satya?"
      }
    ]
  },
  "rankingResponse": {
    "mainline": {
      "items": [
        {
          "answerType": "Facts",
          "value": {
            "id": "https://www.bingapis.com/api/v7/#Facts"
          }
        },
        {
          "answerType": "WebPages",
          "resultIndex": 0,
          "value": {
            "id": "https://www.bingapis.com/api/v7/#WebPages.0"
          }
        },
        {
          "answerType": "WebPages",
          "resultIndex": 1,
          "value": {
            "id": "https://www.bingapis.com/api/v7/#WebPages.1"
          }
        },
        {
          "answerType": "WebPages",
          "resultIndex": 2,
          "value": {
            "id": "https://www.bingapis.com/api/v7/#WebPages.2"
          }
        },
        {
          "answerType": "WebPages",
          "resultIndex": 3,
          "value": {
            "id": "https://www.bingapis.com/api/v7/#WebPages.3"
          }
        },
        {
          "answerType": "WebPages",
          "resultIndex": 4,
          "value": {
            "id": "https://www.bingapis.com/api/v7/#WebPages.4"
          }
        },
        {
          "answerType": "WebPages",
          "resultIndex": 5,
          "value": {
            "id": "https://www.bingapis.com/api/v7/#WebPages.5"
          }
        },
        {
          "answerType": "WebPages",
          "resultIndex": 6,
          "value": {
            "id": "https://www.bingapis.com/api/v7/#WebPages.6"
          }
        },
        {
          "answerType": "WebPages",
          "resultIndex": 7,
          "value": {
            "id": "https://www.bingapis.com/api/v7/#WebPages.7"
          }
        },
        {
          "answerType": "WebPages",
          "resultIndex": 8,
          "value": {
            "id": "https://www.bingapis.com/api/v7/#WebPages.8"
          }
        }
      ]
    },
    "sidebar": {
      "items": [
        {
          "answerType": "Entities"
        },
        {
          "answerType": "Entities",
          "resultIndex": 0,
          "value": {
            "id": "https://www.bingapis.com/api/v7/#Entities.0"
          }
        }
      ]
    }
  }
}

400 Bad Request

Representations

{
  "_type": "ErrorResponse",
  "instrumentation": {},
  "errors": [
    {
      "code": "InvalidRequest",
      "subCode": "ParameterInvalidValue",
      "message": "Parameter has invalid value.",
      "moreDetails": "Query must be a valid URL",
      "parameter": "q"
    }
  ]
}

401 Unauthorized

Representations

{
  "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."
  }
}

403 Forbidden

Representations

{
  "error": {
    "statusCode": 403,
    "message": "Out of call volume quota. Quota will be replenished in 2.12 days."
  }
}

429 Too many requests

Representations

{
  "error": {
    "statusCode": 429,
    "message": "Rate limit is exceeded. Try again in 26 seconds."
  }
}

Code samples

@ECHO OFF

curl -v -X GET "https://api.labs.cognitive.microsoft.com/answersearch/v7.0/search?q={q}&mkt={mkt}?count=10&offset=0&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["count"] = "10";
            queryString["offset"] = "0";
            queryString["safesearch"] = "Moderate";
            var uri = "https://api.labs.cognitive.microsoft.com/answersearch/v7.0/search?q={q}&mkt={mkt}&" + 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://api.labs.cognitive.microsoft.com/answersearch/v7.0/search?q={q}&mkt={mkt}");

            builder.setParameter("count", "10");
            builder.setParameter("offset", "0");
            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
            "count": "10",
            "offset": "0",
            "safesearch": "Moderate",
        };
      
        $.ajax({
            url: "https://api.labs.cognitive.microsoft.com/answersearch/v7.0/search?q={q}&mkt={mkt}&" + $.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://api.labs.cognitive.microsoft.com/answersearch/v7.0/search?q={q}&mkt={mkt}";
    NSArray* array = @[
                         // Request parameters
                         @"entities=true",
                         @"count=10",
                         @"offset=0",
                         @"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://api.labs.cognitive.microsoft.com/answersearch/v7.0/search?q={q}&mkt={mkt}');
$url = $request->getUrl();

$headers = array(
    // Request headers
    'Ocp-Apim-Subscription-Key' => '{subscription key}',
);

$request->setHeader($headers);

$parameters = array(
    // Request parameters
    'count' => '10',
    'offset' => '0',
    '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
    'count': '10',
    'offset': '0',
    'safesearch': 'Moderate',
})

try:
    conn = httplib.HTTPSConnection('api.labs.cognitive.microsoft.com')
    conn.request("GET", "/answersearch/v7.0/search?q={q}&mkt={mkt}&%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
    'count': '10',
    'offset': '0',
    'safesearch': 'Moderate',
})

try:
    conn = http.client.HTTPSConnection('api.labs.cognitive.microsoft.com')
    conn.request("GET", "/answersearch/v7.0/search?q={q}&mkt={mkt}&%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://api.labs.cognitive.microsoft.com/answersearch/v7.0/search?q={q}&mkt={mkt}')

query = URI.encode_www_form({
    # Request parameters
    'count' => '10',
    'offset' => '0',
    'safesearch' => 'Moderate'
})
if query.length > 0
  if uri.query && uri.query.length > 0
    uri.query += '&' + query
  else
    uri.query = query
  end
end

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