Access control error

hi i’m on a project and i get the contacts that are registered on my site which are local to submit them to my hubspot app and i have this message in my console
request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access. this is the code i use
$.ajax({
type: “POST”,
url: api,
crossDomain : true,
xhrFields: {
withCredentials: true
},
headers:{
“content-type”:“json/application”,
“Access-Control-Allow-Origin”:“*”,
“Access-Control-Allow-Headers”:“Origin, X-Requested-With, Content-Type, Accept”
},
data:data1
})
.done(function( data ) {
console.log(“done”);
})
.fail( function(xhr, textStatus, errorThrown) {
alert(xhr.responseText);
alert(textStatus);
});

Hi @maven,

Which endpoint are you using?

As this documentation states, most of HubSpot’s APIs do not support CORS AJAX requests. The only POST method which supports AJAX is for the Forms API.

If you are using the Forms API, please share an example request URL and body which failed.

hi @Isaac_Takushi
thank you I solved it using the API forms

@IsaacTakushi Hi Isaac!

I am a new one with hubspot. And I got the same problem as Maven. I am working on create a support form from my own website to allow the Users to create a tickets and send direct to my hubspot. But I am not able to using Ajax to post the data to create ticket api. As I understand after read your solution that you suggest to Maven. But I don not how to use it. Could you please send me an example using create ticket api? Thank you!

Hi, @MikeDao.

Apologies for the delayed response.

At this time, it is not possible to create tickets via AJAX requests to the Tickets API.

This undocumented workaround uses the v3 Forms API, though, which supports AJAX. Please keep in mind that since it is as yet undocumented, it is subject to breaking changes without notice.