I’m trying to use the Sendgrid API on WordPress, but getting this error
when inspecting.

XMLHttpRequest cannot load https://api.sendgrid.com/v3/mail/send. Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'https://sendgrid.api-docs.io' that is not equal to the supplied origin. Origin 'https://localhost2' is therefore not allowed access.

First I though was a service that requires HTTPS, so I setup https on my local MAMP server but still not working, then I tried multiple strategies, namely changing htaccess file, adding CORS header in the file but nothing really worked.

$http.post('https://api.sendgrid.com/v3/mail/send',mail,{ headers: {
            'Authorization': 'Bearer MY IDENTICATION',
            'Content-Type': 'application/json'
        console.log('Error' + data);
        console.log('Error' + data);

This is the angular function I used to post to the API.

Can anyone help me to explain what exactly the error means( or am I missing anything)

Read more here: Using Sendgrid API with WordPress


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: