I'm trying to implement microsoft translation API. (https://rapidapi.com/microsoft-azure-org-microsoft-cognitive-services/api/microsoft-translator-text)
I want to integrate it with dialog flow and dialog flow doesn't work with axios function so i tried using async function using fetch.
This code is working fine
axios({
"method": "POST",
"url": "https://microsoft-translator-text.p.rapidapi.com/translate",
"headers": {
"content-type": "application/json",
"x-rapidapi-host": "microsoft-translator-text.p.rapidapi.com",
"x-rapidapi-key": "key",
"accept": "application/json",
"useQueryString": true
}, "params": {
"profanityAction": "NoAction",
"textType": "plain",
"to": "hi",
"api-version": "3.0"
}, "data": [{
"Text": "Hello, World"
}]
})
.then((response) => {
console.log(response);
console.log(response.data[0].detectedLanguage.language);
console.log(response.data[0].translations[0].text);
})
.catch((error) => {
console.log(error);
})
But when I use the same code using fetch, its giving the error
async function translate() {
const response = await fetch(`https://microsoft-translator-text.p.rapidapi.com/translate`, {
"method": "POST",
"headers": {
"content-type": "application/json",
"x-rapidapi-host": "microsoft-translator-text.p.rapidapi.com",
"x-rapidapi-key": "key",
"accept": "application/json",
"useQueryString": true
}, "params": {
"profanityAction": "NoAction",
"textType": "plain",
"to": "hi",
"api-version": "3.0"
}, "data": [{
"Text": "Hello, World"
}]
});
const jsonres = await response.json();
console.log(jsonres);
}
translate();
This is the error
error:
code: 400000
message: "One of the request inputs is not valid."
