2

I am trying to create a successful request using Azure's Bing News API. The below screenshot from the docs says that the Ocp-Apim-Subscription-Key is a required header. https://learn.microsoft.com/en-us/rest/api/cognitiveservices-bingsearch/bing-news-api-v7-reference

enter image description here

I've made an account and according to this post Issue in accessing Bing Custom Web Search API v7 the key is found in the Bing Resource -> Keys & Endpoints:enter image description here

I've tried both keys and neither work. I receive error code 401 Access denied due to Invalid subscription key or wrong API endpoint. I noticed that the endpoint featured in this picture is different from the endpoints listed in the bing new docs. I tried the endpoint listed in the picture (just to see) and I got a 404 error.

Another thread says to go to the API Management on the Azure portal. https://learn.microsoft.com/en-us/answers/questions/62385/please-help-me-to-find-the-process-to-get-ampampam.html

Upon navigating to API Management menu it read "No API Management services to display". I can "Create API Management" but the subsequent forms asks for information that seems atypical to gain access to an API. Is this really where the key is created or am I doing something else wrong? Thank you.

Here is my code. I tried on Postman and ran into the same error.

import fetch from 'node-fetch';

function testFetch(){



let response = fetch("https://api.cognitive.microsoft.com/bing/v7.0/news/trendingtopics", {
headers: {
    "Ocp-Apim-Subscription-Key": <redacted-key>,
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  }
}).then(async response => {
  try {
   const data = await response.json()
   console.log('response data?', data)
 } catch(error) {
   console.log('Error happened here!')
   console.error(error)
 }
})


 }

 testFetch()
nizoom
  • 105
  • 6
  • No, you don't need to go to API Management to get this subscription key.. that is required only if you are exposing your API via subscription. You are trying to connect to Bing api with the key provided in the Azure portal for your specific bing resource..check if the http headers are getting passed by sniffing the http request that actually goes out. Make sure you didn't miss any character when pasting the key in Postman headers tab. – Anand Sowmithiran Oct 23 '21 at 17:47
  • BTW, did you try changing to single quote while mentioning the subscription in headers. Node-fetch documentation prefers single quote while framing http headers. – Anand Sowmithiran Oct 23 '21 at 17:56
  • Yes I tried with single quotes and got the same results. Is there an example or documentation available for more information on sniffing an http request? Thank you – nizoom Oct 23 '21 at 23:45
  • To view the actual http request and response information while running the nodejs code, use a tool like Fiddler. See https://docs.telerik.com/fiddler-everywhere/knowledge-base/how-to-capture-nodejs-traffic – Anand Sowmithiran Oct 24 '21 at 06:39

1 Answers1

2

Please use the following endpoint BING_HOST = "https://api.bing.microsoft.com/v7.0/news/search" and find the below snapshot for the same.

Please follow the below documentation for bing news search.

https://learn.microsoft.com/en-us/bing/search-apis/bing-news-search/overview

Ram
  • 2,459
  • 1
  • 7
  • 14