Local Business API - v7

The Bing Local Business API returns local businesses.

Businesses

Get local business results from a given query

Try it

Request URL

Request parameters

string

Bing search query. The query can contain any valid query text that the Bing Engine supports. Because of the implementation all the query operators mentioned on Bing like ‘+’ site:, url:, can be used by the caller. All query specific operators will be separated by the API

(optional)
string

Allows specification of a business category. Supported categories can be high-level such as EatDrink, Shop, SeeDo. Multiple categories can be specified separated by a ','

(optional)
string

Country code

(optional)
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 -. For example, en-us.



Full list of supported markets:
en-us
(optional)
string

Setting used for filtering sexually explicit content. Following levels are supported: Strict, Off, Demote – for Moderate. Fail in case client calls for an invalid adult setting or and adult setting not available for a certain market. Setting this filter to strict removes adult businesses (for example strip clubs, and also strips out business URLs)

(optional)
string

Language in which display strings are expected. Specify the language using the ISO 639-1& 2-letter language code.

(optional)
number

Count of results expected. Maximum that can be passed is 50. This is a maximum value, meaning the backend can return up to the value specified in the count parameter.

(optional)
number

Offset from which results should start. One based offset.

(optional)
string

Latitude, longitude and radius in meter. Note that circular view should only be used to indicate a search around a point on the map, not as an approximation for a view port of a map rectangular.

(optional)
string

Bounding box for results specified in the following format NW_latitude, NW_Longitude, SE_Latitude, SE_Longitude. These values are lat, long pairs for the Northwest corner and the Southeast corner of a rectangle. The API will use this to only return results that lie within this specified rectangle. Note that this is the required way to specify a rectangular view port of a map application.

Request headers

string
Subscription key which provides access to this API. Found in your Cognitive Services accounts.

Request body

Response 200

{
    "_type": "SearchResponse",
    "instrumentation": {
      "_type": "ResponseInstrumentation",
      "pingUrlBase": "https://www.bing-int.com/api/ping?IG=B060EBF555524FB793F3A4B92C5B8433&CID=2BDBE77091C96A50208CEC50905E6BC7&ID=",
      "pageLoadPingUrl": "https://www.bing-int.com/api/ping/pageload?IG=B060EBF555524FB793F3A4B92C5B8433&CID=2BDBE77091C96A50208CEC50905E6BC7&Type=Event.CPT&DATA=0"
    },
    "queryContext": {
      "originalQuery": "American Property Consultants, Seattle"
    },
    "places": {
      "value": [
        {
          "_type": "LocalBusiness",
          "id": "https://localhost/api/v7/#Places.0",
          "readLink": "https://localhost/api/v7/localbusinesses/YN926x19440910",
          "contractualRules": [
            {
              "_type": "ContractualRules/LinkAttribution",
              "text": "Yelp",
              "url": "https://www.yelp.com/biz/american-property-consultants-seattle?adjust_creative=bing&utm_campaign=yelp_feed&utm_medium=bingapi&utm_source=B4E505",
              "urlPingSuffix": "DevEx,5150.1",
              "optionalForListDisplay": true
            }
          ],
          "webSearchUrl": "https://www.bing.com/entityexplore?q=American+Property+Consultants&filters=local_ypid:%22YN926x19440910%22&elv=AXXfrEiqqD9r3GuelwApulothUcgA0QE*72g7lYU*qbd9iqic7I4TTwv3e*Pg969Ep59g31DcyKOEMLIWezBP*7hVCYSDs8DvSdKNWZE*bv9",
          "webSearchUrlPingSuffix": "DevEx,5151.1",
          "name": "American Property Consultants",
          "url": "https://www.facebook.com/American-Property-Consultants-320373097983762/",
          "urlPingSuffix": "DevEx,5152.1",
          "socialMediaInfo": {
            "profiles": [
              {
                "profileId": "320373097983762",
                "profileUrl": "https://www.facebook.com/American-Property-Consultants-320373097983762/",
                "profileUrlPingSuffix": "DevEx,5153.1",
                "socialNetwork": "Facebook"
              }
            ]
          },
          "entityPresentationInfo": {
            "entityScenario": "ListItem",
            "entityTypeHints": [
              "Place",
              "LocalBusiness"
            ]
          },
          "bingId": "YN926x19440910",
          "geo": {
            "latitude": 47.5990104675293,
            "longitude": -122.331916809082
          },
          "routablePoint": {
            "latitude": 47.5992202758789,
            "longitude": -122.33194732666
          },
          "address": {
            "streetAddress": "165 S Jackson St",
            "addressLocality": "Seattle",
            "addressRegion": "WA",
            "postalCode": "98104",
            "addressCountry": "US",
            "neighborhood": "",
            "text": "165 S Jackson St, Seattle, WA, 98104"
          },
          "telephone": "(206) 622-7833",
          "timeZone": "Pacific Standard Time",
          "isPermanentlyClosed": false,
          "categories": [
            "91450",
            "90584",
            "2175",
            "12360"
          ]
        }
      ]
    }
  }

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://api.cognitive.microsoft.com/bing/v7.0/localbusinesses/search?q={string}&localCategories={string}&cc={string}&mkt=en-us&safesearch=Moderate&setlang=en&count=10&first=0&localCircularView={string}&localMapView={string}"
-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"] = "{string}";
            queryString["localCategories"] = "{string}";
            queryString["cc"] = "{string}";
            queryString["mkt"] = "en-us";
            queryString["safesearch"] = "Moderate";
            queryString["setlang"] = "en";
            queryString["count"] = "10";
            queryString["first"] = "0";
            queryString["localCircularView"] = "{string}";
            queryString["localMapView"] = "{string}";
            var uri = "https://api.cognitive.microsoft.com/bing/v7.0/localbusinesses/search?" + queryString;

            var response = await client.GetAsync(uri);
            if (response?.Content != null)
            {
                var responseString = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseString);    
            }
        }
    }
}	
// // 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;
import org.apache.http.entity.StringEntity;

public class JavaSample 
{
    public static void main(String[] args) 
    {
        HttpClient httpclient = HttpClients.createDefault();

        try
        {
            URIBuilder builder = new URIBuilder("https://api.cognitive.microsoft.com/bing/v7.0/localbusinesses/search");

            builder.setParameter("q", "{string}");
            builder.setParameter("localCategories", "{string}");
            builder.setParameter("cc", "{string}");
            builder.setParameter("mkt", "en-us");
            builder.setParameter("safesearch", "Moderate");
            builder.setParameter("setlang", "en");
            builder.setParameter("count", "10");
            builder.setParameter("first", "0");
            builder.setParameter("localCircularView", "{string}");
            builder.setParameter("localMapView", "{string}");

            URI uri = builder.build();
            HttpGet request = new HttpGet(uri);
            request.setHeader("Ocp-Apim-Subscription-Key", "{subscription key}");

            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": "{string}",
            "localCategories": "{string}",
            "cc": "{string}",
            "mkt": "en-us",
            "safesearch": "Moderate",
            "setlang": "en",
            "count": "10",
            "first": "0",
            "localCircularView": "{string}",
            "localMapView": "{string}",
        };
      
        $.ajax({
            url: "https://api.cognitive.microsoft.com/bing/v7.0/localbusinesses/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(JSON.stringify(data));
        })
        .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.cognitive.microsoft.com/bing/v7.0/localbusinesses/search";
    NSArray* array = @[
                         // Request parameters
                         @"entities=true",
                         @"q={string}",
                         @"localCategories={string}",
                         @"cc={string}",
                         @"mkt=en-us",
                         @"safesearch=Moderate",
                         @"setlang=en",
                         @"count=10",
                         @"first=0",
                         @"localCircularView={string}",
                         @"localMapView={string}",
                      ];
    
    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.cognitive.microsoft.com/bing/v7.0/localbusinesses/search');
$url = $request->getUrl();

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

$request->setHeader($headers);

$parameters = array(
    // Request parameters
    'q' => '{string}',
    'localCategories' => '{string}',
    'cc' => '{string}',
    'mkt' => 'en-us',
    'safesearch' => 'Moderate',
    'setlang' => 'en',
    'count' => '10',
    'first' => '0',
    'localCircularView' => '{string}',
    'localMapView' => '{string}',
);

$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 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': '{string}',
    'localCategories': '{string}',
    'cc': '{string}',
    'mkt': 'en-us',
    'safesearch': 'Moderate',
    'setlang': 'en',
    'count': '10',
    'first': '0',
    'localCircularView': '{string}',
    'localMapView': '{string}',
})

try:
    conn = http.client.HTTPSConnection('api.cognitive.microsoft.com')
    conn.request("GET", "/bing/v7.0/localbusinesses/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://api.cognitive.microsoft.com/bing/v7.0/localbusinesses/search')
uri.query = URI.encode_www_form({
    # Request parameters
    'q' => '{string}',
    'localCategories' => '{string}',
    'cc' => '{string}',
    'mkt' => 'en-us',
    'safesearch' => 'Moderate',
    'setlang' => 'en',
    'count' => '10',
    'first' => '0',
    'localCircularView' => '{string}',
    'localMapView' => '{string}'
})

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