How to get BingAPIs-Market response header

2021-04-27T05:29:27.15+00:00

We have a scenario where we need to show the Bing Market/ Region from where the Bing news is being fetched. In the response headers, I am able to see BingAPIs-Market.

  1. I am getting empty object as response headers. Do we need to add any request headers to get response headers
  2. Is there any API to fetch BingAPIs-Market response header
Bing News Search
Bing News Search
A Bing service that supports searching for news and get comprehensive results.
43 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. GiftA-MSFT 11,151 Reputation points
    2021-04-27T20:35:50.303+00:00

    Here's a sample code to fetch the headers. Hope this helps.

    const fetch = require("node-fetch");
    var myHeaders = new fetch.Headers();
    myHeaders.append("Ocp-Apim-Subscription-Key", "ENTER YOUR KEY");
    
    var requestOptions = {
      method: 'GET',
      headers: myHeaders,
      redirect: 'follow'
    };
    
    // search results
    fetch("https://api.bing.microsoft.com/v7.0/news/search?q=microsoft", requestOptions)
      .then(response => response.text())
      .then(result => console.log(result))
      .catch(error => console.log('error', error));
    
    // response headers
    fetch("https://api.bing.microsoft.com/v7.0/news/search?q=microsoft", requestOptions)
      .then(response => response.headers)
      .then(result => console.log(result))
      .catch(error => console.log('error', error));
    
    // BingAPIs-Market
    fetch("https://api.bing.microsoft.com/v7.0/news/search?q=microsoft", requestOptions)
      .then(response => response.headers.get('bingapis-market'))
      .then(result => console.log(result))
      .catch(error => console.log('error', error));
    

  2. GiftA-MSFT 11,151 Reputation points
    2021-05-06T19:52:10.427+00:00

    Quick follow-up on your second question. Users can only pass Market as a query parameter to get results only from that market, and can get market used by the API request as BingAPIs-Market Header. Please refer to the following documents (response objects, headers) for more details. Hope this helps!

    0 comments No comments