0
votes

I try to translate with microsoft/bing text translator api. I have an azure service and valid token from /v1.0/issueToken.

I tried this in my browser and on this testsite: https://docs.microsofttranslator.com/text-translate.html#!/default/get_Translate

text=test
to=en
Authorization=Bearer TOKEN

That's what i got back:

XMLHttpRequest cannot load api.microsofttranslator.com/v2/http.svc/Translate?text=test&to=en. Response for preflight is invalid (redirect)

=> "error": "no response from server"

Does anyone know what the problem is?

2

2 Answers

0
votes

Here's a working example using curl and Windows. Looks like you're missing From query parameter. Always prototype API calls using curlbefore integrating. If it doesn't work with curl, it won't work in your code. Use curl first.

curl -k --data "" "https://api.cognitive.microsoft.com/sts/v1.0/issueToken" -H "Ocp-Apim-Subscription-Key:<Your key here>" > Bearer.txt
set /p Bearer= < Bearer.txt
curl -H "Authorization: Bearer %Bearer%" "https://api.microsofttranslator.com/v2/Http.svc/Translate?Text=test&From=en&To=es"
0
votes

It's working if "Bearer "+ TOKEN is added via appid parameter. Authorization header doesn't work in browser.