question

VenkateshGottimukkulaINFOSYSLIMITE-5039 avatar image
0 Votes"
VenkateshGottimukkulaINFOSYSLIMITE-5039 asked GiftA-MSFT edited

How to get BingAPIs-Market response header

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


azure-bing-news
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GiftA-MSFT avatar image
0 Votes"
GiftA-MSFT answered GiftA-MSFT edited

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));
· 10
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

Please find code snippet below. When I log for response headers, I am getting empty object { } . I know how to add request headers. How can we specify to include response headers.

91916-image.png



Thanks,
Venkatesh

0 Votes 0 ·
image.png (37.5 KiB)
GiftA-MSFT avatar image GiftA-MSFT VenkateshGottimukkulaINFOSYSLIMITE-5039 ·

Hi, thanks for clarifying. Please review my updated answer. Hope this helps!

0 Votes 0 ·

Hi,

I am making Bing News Search API from Browser Client side code (SPFx code ). When I tried to use response.headers.get('bingapis-market')). I am getting null value.

Thanks,
Venkatesh

0 Votes 0 ·
Show more comments
GiftA-MSFT avatar image
0 Votes"
GiftA-MSFT answered GiftA-MSFT edited

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!


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.