Search code examples
azurecomputer-visionazure-cognitive-services

cognitive computer vision api, Initial 202 response from api call, then 401 error from Operation-Location


Running this in a reactjs project, this is my current code:

         let response = await fetch('https://apis-cv.cognitiveservices.azure.com/vision/v1.0/recognizeText?handwriting=true', {
          method: 'POST',
          headers: { 'Content-Type': 'application/octet-stream', 'Ocp-Apim-Subscription-Key': '<MY KEY HERE>' },
          body: this.makeblob(event.target.result)
        });
        console.log(response);

My initial response has status 202: with an Operation-Location given. (i.e https://apis-cv.cognitiveservices.azure.com/vision/v1.0/textOperations/a60b86b2-bf85-4e3b-8beb-65dc075e81d7 ) but the Operation-Location results in a 401:

 {"error":{"code":"401","message":"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 have also tried with a url and content-type: application/json and get the same result.


Solution

  • The error message is quite clear: you forgot to add the 'Ocp-Apim-Subscription-Key' in your second query, when you try to get the result of your TextOperations.

    Can you add your implementation of how you try to get the result?