Bertrand PETIT
Bertrand PETIT

Reputation: 31

Deepl Api request blocked by CORS policy

I have integrated Deepl API in our Web CRM since a few months. It was working fine until a few days ago. I don't know when exactly, but maybe since the new year.

Now, all requests are blocked by CORS policy :

Access to XMLHttpRequest at 'https://api-free.deepl.com/v2/translate?auth_key=xxxxxxxxxxxxxxxx:fx&target_lang=DE&preserve_formatting=1&split_sentences=0&text=bonjour' from origin 'https://example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I'm sending requests via jQuery ajax :

var url = "https://api-free.deepl.com/v2/translate?auth_key=xxxxxxxxxxxxxxxx:fx&target_lang=DE&preserve_formatting=1&split_sentences=0&text=bonjour";
$.ajax({
    url,
    type: 'GET',
    success: (translations) => {
        console.log(translations);
    }
});

Any ideas why please ?

I tried from local website in http and from production site in https, same result.

It's working well with Postman app.

Upvotes: 1

Views: 640

Answers (1)

Bertrand PETIT
Bertrand PETIT

Reputation: 31

I solved my issue by installing the Deepl library on my server (Php in my case). Instead of calling the Deepl API directly from my JS, I send my requests to my server. More info on Client libraries : https://www.deepl.com/fr/docs-api/api-access/client-libraries/

Thanks to @John Smith

Upvotes: 2

Related Questions