1
votes

I suscribed for the free Azure trial to use the Dictionary Lookup feature and got this endpoint and (redacted) API key :

Grab your keys and endpoint

key1

084***13

Endpoint

https://westeurope.api.cognitive.microsoft.com/

Every call to Cognitive Services requires the subscription key above. This key needs to be either passed through a query string parameter or specified in the request header. To manage your keys, use the Keys option from the left menu

Then on this page I find a simple example, where it seems I just have to substitute the key:

curl -X POST "https://api.cognitive.microsofttranslator.com/dictionary/lookup?api-version=3.0&from=en&to=es" -H "Ocp-Apim-Subscription-Key: <client-secret>" -H "Content-Type: application/json" -d "[{'Text':'fly'}]"

I test it in my command line, replacing the key, but no success :

curl -X POST "https://api.cognitive.microsofttranslator.com/dictionary/lookup?api-version=3.0&from=en&to=es" -H "Ocp-Apim-Subscription-Key: 084***13" -H "Content-Type: application/json" -d "[{'Text':'fly'}]

{"error":{"code":401000,"message":"The request is not authorized because credentials are missing or invalid."}}

I try to change the endpoint, but no success either :

curl -X POST "https://westeurope.api.cognitive.microsoft.com/dictionary/lookup?api-version=3.0&from=en&to=es" -H "Ocp-Apim-Subscription-Key: 084***13" -H "Content-Type: application/json" -d "[{'Text':'fly'}]

{"error":{"code":"404","message": "Resource not found"}}

I assume I'm missing something obvious but the doc isn't exactly newb friendly. What should I do ?

1

1 Answers

2
votes

You need to add a region!

It depends on which resource you subscribed for, because there are 2 options, the Translator Text API and Cognitive Services multi-service API

I can see you went with Cognitive Services multi-service so, in that case you need to add the Ocp-Apim-Subscription-Region value which is stated in the documentation

When you use a multi-service secret key, you must include two authentication headers with your request. The first passes the secret key, the second specifies the region associated with your subscription.

  • Ocp-Apim-Subscription-Key
  • Ocp-Apim-Subscription-Region

I added it below, you just need to replace <your-key> and <your-region> with your own!

curl -X POST "https://api.cognitive.microsofttranslator.com/dictionary/lookup?api-version=3.0&from=en&to=es" -H "Ocp-Apim-Subscription-Key: <your-key>" -H "Ocp-Apim-Subscription-Region: <your-region>" -H "Content-Type: application/json" -d "[{'Text':'fly'}]"