So I have this method in my Angular Node.js app:
async translateWord(word: string) {
const key = '*I put it here*';
const translation = await axios({
"method": "POST",
"url": "https://google-translate1.p.rapidapi.com/language/translate/v2",
"headers": {
"content-type": "application/octet-stream",
"x-rapidapi-host": "google-translate1.p.rapidapi.com",
"x-rapidapi-key": key,
"useQueryString":true
},
"data": {
"source": "en",
"q": word,
"target": "ru"
}
});
console.log(translation.data);
}
The result of calling the method is
POST https://google-translate1.p.rapidapi.com/language/translate/v2 502 (Bad Gateway)
When I right-click on the failed request in Chrome dev tools window and open it in new tab, I get the following message:
{"message":"Missing RapidAPI application key. Go to https://docs.rapidapi.com/docs/keys to learn how to get your API application key."}
The weird thing is that I actually have the key in my headers: proof
Also I get the correct translation when I execute the same code snippet via RapidApi interface.
RapidAPI supports passing the API key via a query parameter. You can do this by including the following syntax in the link:
https://example.p.rapidapi.com/?rapidapi-key=***************************
However, please keep in mind that your RapidAPI key is used across your entire account. Be careful about exposing your key if the link is publicly accessible.