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
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:
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()
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