@Anil Samuel Thanks for the question. Please follow the below guidance to use the translator to translate text using node.js and javascript .
https://learn.microsoft.com/en-us/azure/cognitive-services/Translator/quickstart-translate?pivots=programming-language-javascript
https://github.com/Azure-Samples/cognitive-services-quickstart-code/blob/master/javascript/TranslatorText/Translate.js
Translate API : One of the request inputs is not valid.
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));
}
1 answer
Sort by: Most helpful
-
Ramr-msft 17,736 Reputation points
2020-07-31T08:00:17.89+00:00