Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access denied due to invalid subscription key (Face API)

I am having trouble using Microsoft Face API. Below is my sample request:

curl -v -X POST "https://westus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: 1xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxd" --data-ascii "{\"url\":\"http://www.mrbeantvseries.co.uk/bean3.jpg\"}"

I use the subscription id from my cognitive services account and I got below response:

{
  "error": {
    "code": "Unspecified",
    "message": "Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key."
  }
}

Not sure if I've missed out anything there. Can someone help me on this? Very much appreciated.

like image 271
Ahmad Farhan Avatar asked Feb 08 '17 21:02

Ahmad Farhan


People also ask

How to fix 401 unauthorized error Azure?

Make sure to provide a valid key for an active subscription." "statusCode": 401, "message": "Access denied due to missing subscription key. Make sure to include subscription key when making requests to an API."

Where do I find my OCP-Apim-subscription-key?

The subscription key can be found under user profile in the API Manager Portal. The subscription key is assigned to the Ocp-Apim-Subscription-Key parameter the header.

How do I use OCP-Apim-subscription-key in Postman?

Creating a Request in Postman Paste the Request URL and enter any Request Parameter values in the URL. Select the proper verb from the dropdown. Under the Headers tab: In the KEY column, enter "ocp-apim-subscription-key"


2 Answers

I ran into the same problem. I read the API documentation and it states the following.

You must use the same region in your REST API call as you used to obtain your subscription keys.

First, you must find the location of your subscription. In order to find the location of your subscription region, you must go to Cognitive Services -> Properties under the Label Location, you will find your subscription region. See below. enter image description here

Second you must find the correct endpoint to make the call to. For example, if I want to make a call to the Computer Vision API, My location is East US, I will use either key 1 or 2, then I will use the following endpoint East US - https://eastus.api.cognitive.microsoft.com/face/v1.0/detect

You will now be able to have access to the API.

like image 133
CesarB Avatar answered Nov 11 '22 15:11

CesarB


It appears that you've entered your Azure subscription ID instead? In the Azure portal, you can find the API key under 'Keys', shown below:

Azure Portal screenshot

It will be a 32-digit hexadecimal number, no hyphens.

like image 36
cthrash Avatar answered Nov 11 '22 14:11

cthrash