I am currently experiencing an issue with the Deepl API. When I make a request using Postman, it is successful. However, when trying to use it in my app, I only receive a 400 Error response. I suspect that this may be due to incorrect headers setup, even though they match what I have in Postman. Can anyone help me identify what might be causing this problem?
async translateMessage(data = {}) {
const url = "https://api.deepl.com/v2/translate?auth_key=myAuthKey";
const response = await fetch(url, {
method: "POST",
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': '*/*'
},
body: {
text: JSON.stringify(this.text),
target_lang: 'DE',
source_lang: 'EN'
}
});
return response.json();
},
You can refer to an example HTTP Post Request from the Documentation here.
POST /v2/translate?auth_key=[yourAuthKey]> HTTP/1.0
Host: api.deepl.com
User-Agent: YourApp
Accept: */*
Content-Length: [length]
Content-Type: application/x-www-form-urlencoded
auth_key=[yourAuthKey]&text=Hello, world&source_lang=EN&target_lang=DE