Translate API : One of the request inputs is not valid.

Anil Samuel 6 Reputation points
2020-07-30T05:03:33.11+00:00

curl -k -X POST "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=zh-Hans" -H "Ocp-Apim-Subscription-Key: xxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json; charset=UTF-8" -d "[{'Text':'Hello, what is your name?'}]"

Curl command above works with my subscription key but the equivalent in browser / client javascript below result HTTP 400 error with message as "One of the request inputs is not valid."

$.post({
url: 'https://api.cognitive.microsofttranslator.com/translate?' + jQuery.param({
'api-version': '3.0',
'to': 'zh-Hans'
}),
beforeSend: function (xhr) {
xhr.setRequestHeader("Ocp-Apim-Subscription-Key", "xxxxxxxxxxxxxxxxxxxxx");
},
dataType: 'json',
contentType: 'application/json',
processData: false,
data: [{
'Text': 'Hello, what is your name?'
}],
success: function (data) {
console.info(JSON.stringify(data));
},
error: function (data) {
console.error(JSON.stringify(data));
}

Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,181 questions
Azure Translator
Azure Translator
An Azure service to easily conduct machine translation with a simple REST API call.
352 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Ramr-msft 17,621 Reputation points
    2020-07-31T08:00:17.89+00:00