3
votes

I'm trying to make work this very simple example of the Microsoft Cognitive Services in JavaScript but it's not working. I don't know why. Can some one help me or provide a working example?

I've tried to make the code work both in node and browser (of course with the right modifications to the code).

I'm getting this error in node:

"statusCode":404,"message":"Resource not found".

While if I run the code example [provided on the website][1] I get this error:

Access Denied (401): Access denied due to invalid subscription key

(which is weird cause I'm copying the precise key that has been provide to my in my account page).

const cognitiveServices = require('cognitive-services');

const computerVision = cognitiveServices.computerVision({
        API_KEY: "myAPIkey"
});
const parameters = {
    "language": "unk",
    "detectOrientation": "true",
    "content-type": "application/json"
};
const body = {
    "url": "https://upload.wikimedia.org/wikipedia/commons/2/23/Space_Needle_2011-07-04.jpg"
};

computerVision.ocr({
        parameters,
        body
})
.then((response) => {
        console.log('Got response', response);
})
.catch((err) => {
        console.error('Encountered error making request:', err);
});
1
Have you signed up your Azure account to use the cognitive APIs? - volatilevar
@volatilevar I have created the API key following the guide in this link: link. Now I have 2 API keys provided in this page: link. - Jacob
Could you please try removing line "content-type": "application/json" in your parameters? - volatilevar
@volatilevar I've removed it but I still get the error: {"statusCode":404,"message":"Resource not found"} - Jacob
Could you please also remove the quotes around "language" and "detectOrientation" to make it: const parameters = { language: "unk", detectOrientation: "true"}. Also the quotes around "url" - volatilevar

1 Answers

3
votes

Please download version 0.2.0 and it should work.