Bing Answer SearchAPI takes a query parameter and returns a searchResponse
with answerType
: facts
or entities
.
Applications that use the Answer Search API send requests to the endpoint with a URL to preview in a query parameter. The request must include the q=searchTerm
parameter and Ocp-Apim-Subscription-Key header.
The JSON response can be parsed for facts and entities that contain details about the object of search.
To request Answer Search results, send a request to the following endpoint. Use the headers and URL parameters to define further specifications.
Endpoint GET:
https://api.labs.cognitive.microsoft.com/answerSearch/v7.0/search?q=<searchTerm>&subscription-key=0123456789ABCDEF&mkt=en-us
The request must use the HTTPS protocol and include following query parameter:
q=<URL>
- The query that identifies the object of search
For examples that show how to make requests, see C# quickstart or Java quickstart.
The following sections provide technical details about the response objects, query parameters, and headers that affect the search results.
For information about headers that requests should include, see Headers.
For information about query parameters that requests should include, see Query parameters.
For information about the JSON objects that the response includes, see Response objects.
The maximum query URL length is 2,048 characters. To ensure that your URL length does not exceed the limit, the maximum length of your query parameters should be less than 1,500 characters. If the URL exceeds 2,048 characters, the server returns 404 Not found.
For information about permitted use and display of results, see Use and display requirements.
Note
Some request headers that are meaningful for other search APIs don’t affect URL Preview
- Pragma – the caller does not have control over whether URL Preview uses cache
- Cache-Control – the caller does not have control over whether URL Preview uses cache
- User-Agent
Also, some parameters are not currently meaningful for URL Preview API, but may be used in the future for improved globalization.
The following are the headers that a request and response may include.
Header | Description |
---|---|
Accept | Optional request header. The default media type is application/json. To specify that the response use JSON-LD, set the Accept header to application/ld+json. |
Accept-Language | Optional request header. A comma-delimited list of languages to use for user interface strings. The list is in decreasing order of preference. For more information, including expected format, see RFC2616. This header and the setLang query parameter are mutually exclusive—do not specify both. If you set this header, you must also specify the cc query parameter. To determine the market to return results for, Bing uses the first supported language it finds from the list and combines it with the cc parameter value. If the list does not include a supported language, Bing finds the closest language and market that supports the request or it uses an aggregated or default market for the results. To determine the market that Bing used, see the BingAPIs-Market header.Use this header and the cc query parameter only if you specify multiple languages. Otherwise, use the mkt and setLang query parameters.A user interface string is a string that's used as a label in a user interface. There are few user interface strings in the JSON response objects. Any links to Bing.com properties in the response objects apply the specified language. |
BingAPIs-Market | Response header. The market used by the request. The form is <languageCode>-<countryCode>. For example, en-US. |
BingAPIs-TraceId | Response header. The ID of the log entry that contains the details of the request. When an error occurs, capture this ID. If you are not able to determine and resolve the issue, include this ID along with the other information that you provide the Support team. |
Ocp-Apim-Subscription-Key | Required request header. The subscription key that you received when you signed up for this service in Cognitive Services. |
Pragma | Optional request header By default, Bing returns cached content, if available. To prevent Bing from returning cached content, set the Pragma header to no-cache (for example, Pragma: no-cache). |
User-Agent | Optional request header. The user agent originating the request. Bing uses the user agent to provide mobile users with an optimized experience. Although optional, you are encouraged to always specify this header. The user-agent should be the same string that any commonly used browser sends. For information about user agents, see RFC 2616. The following are examples of user-agent strings.
|
X-MSEdge-ClientID | Optional request and response header. Bing uses this header to provide users with consistent behavior across Bing API calls. Bing often flights new features and improvements, and it uses the client ID as a key for assigning traffic on different flights. If you do not use the same client ID for a user across multiple requests, then Bing may assign the user to multiple conflicting flights. Being assigned to multiple conflicting flights can lead to an inconsistent user experience. For example, if the second request has a different flight assignment than the first, the experience may be unexpected. Also, Bing can use the client ID to tailor web results to that client ID’s search history, providing a richer experience for the user. Bing also uses this header to help improve result rankings by analyzing the activity generated by a client ID. The relevance improvements help with better quality of results delivered by Bing APIs and in turn enables higher click-through rates for the API consumer. IMPORTANT: Although optional, you should consider this header required. Persisting the client ID across multiple requests for the same end user and device combination enables 1) the API consumer to receive a consistent user experience, and 2) higher click-through rates via better quality of results from the Bing APIs. The following are the basic usage rules that apply to this header.
NOTE: Bing responses may or may not include this header. If the response includes this header, capture the client ID and use it for all subsequent Bing requests for the user on that device. NOTE: If you include the X-MSEdge-ClientID, you must not include cookies in the request. |
X-MSEdge-ClientIP | Optional request header. The IPv4 or IPv6 address of the client device. The IP address is used to discover the user's location. Bing uses the location information to determine safe search behavior. NOTE: Although optional, you are encouraged to always specify this header and the X-Search-Location header. Do not obfuscate the address (for example, by changing the last octet to 0). Obfuscating the address results in the location not being anywhere near the device's actual location, which may result in Bing serving erroneous results. |
X-Search-Location | Optional request header. A semicolon-delimited list of key/value pairs that describe the client's geographical location. Bing uses the location information to determine safe search behavior and to return relevant local content. Specify the key/value pair as <key>:<value>. The following are the keys that you use to specify the user's location.
NOTE: You are encouraged to always specify the user's geographical location. Providing the location is especially important if the client's IP address does not accurately reflect the user's physical location (for example, if the client uses VPN). For optimal results, you should include this header and the X-MSEdge-ClientIP header, but at a minimum, you should include this header. |
Note
Remember that the Terms of Use require compliance with all applicable laws, including regarding use of these headers. For example, in certain jurisdictions, such as Europe, there are requirements to obtain user consent before placing certain tracking devices on user devices.
The request may include the following query parameters. See the Required column for required parameters. You must URL encode the query parameters.
Name | Value | Type | Required |
---|---|---|---|
mkt | The market where the results come from. For a list of possible market values, see Market Codes. NOTE: The URL Preview API currently only supports en-us market and language. |
String | Yes |
q | The URL to preview | String | Yes |
responseFormat | The media type to use for the response. The following are the possible case-insensitive values.
The default is JSON. For information about the JSON objects that the response contains, see Response Objects. If you specify JsonLd, the response body includes JSON-LD objects that contain the search results. For information about the JSON-LD, see JSON-LD. |
String | No |
safeSearch | A filter used to filter adult content. The following are the possible case-insensitive filter values.
The default is Moderate. NOTE: If the request comes from a market that Bing's adult policy requires that safeSearch is set to Strict, Bing ignores the safeSearch value and uses Strict.NOTE: If you use the site: query operator, there is the chance that the response may contain adult content regardless of what the safeSearch query parameter is set to. Use site: only if you are aware of the content on the site and your scenario supports the possibility of adult content. |
String | No |
setLang | The language to use for user interface strings. Specify the language using the ISO 639-1 2-letter language code. For example, the language code for English is EN. The default is EN (English). Although optional, you should always specify the language. Typically, you set setLang to the same language specified by mkt unless the user wants the user interface strings displayed in a different language.This parameter and the Accept-Language header are mutually exclusive—do not specify both. A user interface string is a string that's used as a label in a user interface. There are few user interface strings in the JSON response objects. Also, any links to Bing.com properties in the response objects apply the specified language. |
String | No |
The response schema is either a [WebPage] or ErrorResponse, as in the Web Search API. If the request fails, the top-level object is the ErrorResponse object.
Object | Description |
---|---|
[WebPage] | Top level JSON object that contains attributes of preview. |
[Fact] | Top level JSON object that contains facts. |
[Entities | Top level JSON object that contains entity details. |
Defines the error that occurred.
Element | Description | Type |
---|---|---|
code | The error code that identifies the category of error. For a list of possible codes, see Error Codes. | String |
message | A description of the error. | String |
moreDetails | A description that provides additional information about the error. | String |
parameter | The query parameter in the request that caused the error. | String |
subCode | The error code that identifies the error. For example, if code is InvalidRequest, subCode may be ParameterInvalid or ParameterInvalidValue. |
String |
value | The query parameter's value that was not valid. | String |
The top-level object that the response includes when the request fails.
Name | Value | Type |
---|---|---|
_type | Type hint. | String |
errors | A list of errors that describe the reasons why the request failed. | Error |
Defines the license under which the text or photo may be used.
Name | Value | Type |
---|---|---|
name | The name of the license. | String |
url | The URL to a website where the user can get more information about the license. Use the name and URL to create a hyperlink. |
String |
Defines a contractual rule for license attribution.
Name | Value | Type |
---|---|---|
_type | A type hint, which is set to LicenseAttribution. | String |
license | The license under which the content may be used. | License |
licenseNotice | The license to display next to the targeted field. For example, "Text under CC-BY-SA license". Use the license's name and URL in the license field to create a hyperlink to the website that describes the details of the license. Then, replace the license name in the licenseNotice string (for example, CC-BY-SA) with the hyperlink you just created. |
String |
mustBeCloseToContent | A Boolean value that determines whether the contents of the rule must be placed in close proximity to the field that the rule applies to. If true, the contents must be placed in close proximity. If false, or this field does not exist, the contents may be placed at the caller's discretion. | Boolean |
targetPropertyName | The name of the field that the rule applies to. | String |
Defines the components of a hyperlink.
Name | Value | Type |
---|---|---|
_type | Type hint. | String |
text | The display text. | String |
url | A URL. Use the URL and display text to create a hyperlink. | String |
Defines a contractual rule for link attribution.
Name | Value | Type |
---|---|---|
_type | A type hint, which is set to LinkAttribution. | String |
mustBeCloseToContent | A Boolean value that determines whether the contents of the rule must be placed in close proximity to the field that the rule applies to. If true, the contents must be placed in close proximity. If false, or this field does not exist, the contents may be placed at the caller's discretion. | Boolean |
targetPropertyName | The name of the field that the rule applies to. If a target is not specified, the attribution applies to the entity as a whole and should be displayed immediately following the entity presentation. If there are multiple text and link attribution rules that do not specify a target, you should concatenate them and display them using a "Data from: " label. For example, “Data from <provider name1> | <provider name2>". |
String |
text | The attribution text. | String |
url | The URL to the provider's website. Use text and URL to create of hyperlink. |
String |
Defines a contractual rule for media attribution.
Name | Value | Type |
---|---|---|
_type | A type hint, which is set to MediaAttribution. | String |
mustBeCloseToContent | A Boolean value that determines whether the contents of the rule must be placed in close proximity to the field that the rule applies to. If true, the contents must be placed in close proximity. If false, or this field does not exist, the contents may be placed at the caller's discretion. | Boolean |
targetPropertyName | The name of the field that the rule applies to. | String |
url | The URL that you use to create of hyperlink of the media content. For example, if the target is an image, you would use the URL to make the image clickable. | String |
Defines a publisher.
Note that a publisher may provide their name or their website or both.
Name | Value | Type |
---|---|---|
name | The publisher's name. | String |
url | The URL to the publisher's website. Note that the publisher may not provide a website. |
String |
Defines information about a the Web page in preview.
Name | Value | Type |
---|---|---|
name | The page title, not necessarily the HTML title | String |
url | The URL that was actually crawled (request may have followed redirects) | String |
description | Brief description of the page and content | String |
isFamilyFriendly | Most accurate for items in the web index; realtime fetches do this detection based solely on the URL and not the page content | boolean |
primaryImageOfPage/contentUrl | The URL to a representative image to include in the preview | String |
Defines the query context that Bing used for the request.
Element | Description | Type |
---|---|---|
adultIntent | A Boolean value that indicates whether the specified query has adult intent. The value is true if the query has adult intent; otherwise, false. | Boolean |
alterationOverrideQuery | The query string to use to force Bing to use the original string. For example, if the query string is saling downwind, the override query string will be +saling downwind. Remember to encode the query string which results in %2Bsaling+downwind. This field is included only if the original query string contains a spelling mistake. |
String |
alteredQuery | The query string used by Bing to perform the query. Bing uses the altered query string if the original query string contained spelling mistakes. For example, if the query string is saling downwind , the altered query string will be sailing downwind .This field is included only if the original query string contains a spelling mistake. |
String |
askUserForLocation | A Boolean value that indicates whether Bing requires the user's location to provide accurate results. If you specified the user's location by using the X-MSEdge-ClientIP and X-Search-Location headers, you can ignore this field. For location aware queries, such as "today's weather" or "restaurants near me" that need the user's location to provide accurate results, this field is set to true. For location aware queries that include the location (for example, "Seattle weather"), this field is set to false. This field is also set to false for queries that are not location aware, such as "best sellers". |
Boolean |
originalQuery | The query string as specified in the request. | String |
Name | Value | Type |
---|---|---|
id | A resource identifier | String |
Defines a search results group, such as mainline.
Name | Value | Type |
---|---|---|
items | A list of search results to display in the group. | RankingItem |
Defines a search result item to display.
Name | Value | Type |
---|---|---|
resultIndex | A zero-based index of the item in the answer to display. If the item does not include this field, display all items in the answer. For example, display all news articles in the News answer. | Integer |
answerType | The answer that contains the item to display. For example, News. Use the type to find the answer in the SearchResponse object. The type is the name of a SearchResponse field. However, use the answer type only if this object includes the value field; otherwise, ignore it. |
String |
textualIndex | The index of the answer in textualAnswers to display. | Unsigned Integer |
value | The ID that identifies either an answer to display or an item of an answer to display. If the ID identifies an answer, display all items of the answer. | Identifiable |
Defines where on the search results page content should be placed and in what order.
Name | Value |
---|---|
mainline | The search results to display in the mainline. |
pole | The search results that should be afforded the most visible treatment (for example, displayed above the mainline and sidebar). |
sidebar | The search results to display in the sidebar. |
Defines the top-level object that the response includes when the request succeeds.
Note that if the service suspects a denial of service attack, the request will succeed (HTTP status code is 200 OK); however, the body of the response will be empty.
Name | Value | Type |
---|---|---|
_type | Type hint, which is set to SearchResponse. | String |
WebPage | A JSON object that defines the preview | string |
Defines a contractual rule for plain text attribution.
Name | Value | Type |
---|---|---|
_type | A type hint, which is set to TextAttribution. | String |
text | The attribution text. Text attribution applies to the entity as a whole and should be displayed immediately following the entity presentation. If there are multiple text or link attribution rules that do not specify a target, you should concatenate them and display them using a "Data from: " label. |
String |
The following are the possible HTTP status codes that a request returns.
Status Code | Description |
---|---|
200 | Success. |
400 | One of the query parameters is missing or not valid. |
401 | The subscription key is missing or is not valid. |
403 | The user is authenticated (for example, they used a valid subscription key) but they don’t have permission to the requested resource. Bing may also return this status if the caller exceeded their queries per month quota. |
410 | The request used HTTP instead of the HTTPS protocol. HTTPS is the only supported protocol. |
429 | The caller exceeded their queries per second quota. |
500 | Unexpected server error. |
If the request fails, the response contains an ErrorResponse object, which contains a list of Error objects that describe what caused of error. If the error is related to a parameter, the parameter
field identifies the parameter that is the issue. And if the error is related to a parameter value, the value
field identifies the value that is not valid.
{
"_type": "ErrorResponse",
"errors": [
{
"code": "InvalidRequest",
"subCode": "ParameterMissing",
"message": "Required parameter is missing.",
"parameter": "q"
}
]
}
{
"_type": "ErrorResponse",
"errors": [
{
"code": "InvalidAuthorization",
"subCode": "AuthorizationMissing",
"message": "Authorization is required.",
"moreDetails": "Subscription key is not recognized."
}
]
}
The following are the possible error code and sub-error code values.
Code | SubCode | Description |
---|---|---|
ServerError | UnexpectedError ResourceError NotImplemented |
HTTP status code is 500. |
InvalidRequest | ParameterMissing ParameterInvalidValue HttpNotAllowed Blocked |
Bing returns InvalidRequest whenever any part of the request is not valid. For example, a required parameter is missing or a parameter value is not valid. If the error is ParameterMissing or ParameterInvalidValue, the HTTP status code is 400. If you use the HTTP protocol instead of HTTPS, Bing returns HttpNotAllowed, and the HTTP status code is 410. |
RateLimitExceeded | No sub-codes | Bing returns RateLimitExceeded whenever you exceed your queries per second (QPS) or queries per month (QPM) quota. If you exceed QPS, Bing returns HTTP status code 429, and if you exceed QPM, Bing returns 403. |
InvalidAuthorization | AuthorizationMissing AuthorizationRedundancy |
Bing returns InvalidAuthorization when Bing cannot authenticate the caller. For example, the Ocp-Apim-Subscription-Key header is missing or the subscription key is not valid.Redundancy occurs if you specify more than one authentication method. If the error is InvalidAuthorization, the HTTP status code is 401. |
InsufficientAuthorization | AuthorizationDisabled AuthorizationExpired |
Bing returns InsufficientAuthorization when the caller does not have permissions to access the resource. This can occur if the subscription key has been disabled or has expired. If the error is InsufficientAuthorization, the HTTP status code is 403. |