1

I am trying to use Azure News Search in my NodeJS App. The code for the router is here:

const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;
let credentials = new CognitiveServicesCredentials('apikey');
let search_term = 'Winter Olympics'
const NewsSearchAPIClient = require('azure-cognitiveservices-newssearch');
let client = new NewsSearchAPIClient(credentials);
client.newsOperations.search(search_term).then((result) => {
    console.log(result.value);
}).catch((err) => {
    throw err;
});

I get an error:

Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.

I made sure my API key is correct. The code sample is straight from Azure's Quickstart quide. There is no mention of the endpoint there. I feel like I am missing something but can't figure out what.

Thanks in advance for any guidance.

Stanley Gong
  • 11,522
  • 1
  • 8
  • 16
goryef
  • 1,337
  • 3
  • 22
  • 37

1 Answers1

1

Try this to specify your endpoint :

const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;
let credentials = new CognitiveServicesCredentials('<api key>');
let search_term = 'Winter Olympics'
const NewsSearchAPIClient = require('azure-cognitiveservices-newssearch');


let client = new NewsSearchAPIClient(credentials,{"endpoint":"<endpoint url>"});

client.newsOperations.search(search_term,{"count":1}).then((result) => {
    console.log(result.value);
}).catch((err) => {
    console.log(err);
    throw err;
});

Result :

enter image description here

Hope it helps .

Community
  • 1
  • 1
Stanley Gong
  • 11,522
  • 1
  • 8
  • 16
  • Thank You very much. That was it. Another issue now, that return is limited to 10 entries. Any ideas where that is controlled? – goryef Nov 20 '19 at 14:43
  • 1
    @goryef , I have updated the code , just specify the count value in search function will be able to do that . – Stanley Gong Nov 21 '19 at 02:16