Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response.

var settings = {
 "url": "url link",
 "method": "DELETE",
 "timeout": 0,
};

$.ajax(settings).done(function (response) {
 console.log(response);
});

The above code was generated from postman. When I send a request via postman app, it works; however, when I post the same code generated from postman on my app, it throws an error.

 $.ajax({
 url: "url link",,
 type: 'DELETE',
 headers: {
 'Access-Control-Allow-Origin': '*',
 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, Z-Key',
 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
 "Content-type": "application/json",
 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"

 },
 success: function(result) {
 console.log("deleted");
 console.log(result);
 }
});

I have even tried the above code by setting ‘Access-Control-Allow-Methods’: ‘GET, POST, PUT, DELETE, OPTIONS’. But I still receive the same error: “Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response.”

@stefen ,

Didn’t you write something up about this at one point or am I making it up?

@dennisedson @SSawant haha yep! The majority of HubSpot APIs do not allow client side cross origin requests so you have to setup an intermediate server to handle that for you. here’s the article I wrote: How to Enable CORS/AJAX Requests for any HubSpot API

Good to know I am not crazy! Thanks!