I have the Bing Custom Search working in the Azure portal and on customsearch.ai, but when I try to access the endpoint from Postman or a js file I get this error:
error: {
code: '401',
message: 'The Search Operation under Web Search API - v7 is not supported with the current subscription key and pricing tier Bing.CustomSearch.F0.'
}
This is the code I am running. The subscription key is definitely correct. When I change it I get a different error.
const https = require('https');
const SUBSCRIPTION_KEY = "*****************************"
if (!SUBSCRIPTION_KEY) {
throw new Error('AZURE_SUBSCRIPTION_KEY is not set.')
}
function bingWebSearch(query) {
https.get({
hostname: 'api.bing.microsoft.com',
path: '/v7.0/search?q=' + encodeURIComponent(query),
headers: { 'Ocp-Apim-Subscription-Key': SUBSCRIPTION_KEY },
}, res => {
let body = ''
res.on('data', part => body += part)
res.on('end', () => {
for (var header in res.headers) {
if (header.startsWith("bingapis-") || header.startsWith("x-msedge-")) {
console.log(header + ": " + res.headers[header])
}
}
console.log('\nJSON Response:\n')
console.dir(JSON.parse(body), { colors: false, depth: null })
})
res.on('error', e => {
console.log('Error: ' + e.message)
throw e
})
})
}
const query = process.argv[2] || 'Microsoft Bing Search Services'
bingWebSearch(query)