I've been working on this, and I believe the problem is somewhere in the following though I can't for the life of me figure out what I did wrong. I'm getting the generic 400 error which makes me thing I'm passing information incorrectly. For context I'm using C# in Unity (no particular reason why, I'm just brushing up on it. I'm aware there are better things to use). I can post the full project code if needed. Any idea what I'm doing wrong?
private void TranslateText(string textToTranslate, string targetLanguage)
{
string deepLApiUrl = "https://api-free.deepl.com/v2/translate";
string postData = $"source_lang=auto&target_lang={targetLanguage}&text={Uri.EscapeDataString(textToTranslate)}";
UnityWebRequest webRequest = UnityWebRequest.Post(deepLApiUrl, postData);
webRequest.SetRequestHeader("Authorization", "DeepL-Auth-Key " + apiKey);
webRequest.SetRequestHeader("User-Agent", "YourApp/1.2.3");
StartCoroutine(SendTranslationRequest(webRequest));
}
I am passing a request to translate a simple sentence from Spanish to English through unity webrequest to deepl but I'm getting an error 400. To me it appears the arguments and syntax are correct but something must be wrong for the error to occur.
You should omit the
source_langparameter to use automatic language detection; the value "auto" will be rejected by the DeepL API. See the docs here: https://www.deepl.com/docs-api/translate-textIf you continue to receive 400 errors, you should inspect the response body, it will include an error message explaining the problem.