Problem with CORS Domain


#1

We have a custom domain and we try to make requests on Hubspot API, but, the requisitions doesn’t allowed by API.

All files are in the Hubspot Server, someone can help me?

Thanks;


#2

Hi @caico,

At this time, HubSpot APIs do not support support cross-origin (CORS) AJAX requests. Making the request client-side using JavaScript would expose any authentication you’re using for the request. For this reason, I’ve deleted the screenshot you attached (since your hapikey was visible). You might want to consider deactivating that hapikey and generating a new one since it was visible on the forum for a while.

In order to use JavaScript/AJAX, you would need to make the request (excluding any authentication) to an external server that could then add the needed authentication and make requests to HubSpot’s APIs server-side.


#3

Ok, I’ll change the hapikey but, the recommendation is to use an external server and not use the API within Hubspot?


#4

Hi @caico,

Yes: In order to make AJAX requests, you have to make your requests to an external server, since the HubSpot CMS doesn’t support CORS requests.


#5

If my JavaScript file is on an external server but being called inside the Hubspot platform should it work? Or should I build my entire platform off to use the API?


#6

Hi @caico,

The issue comes from the fact that you’re making cross origin requests, not with where the JavaScript file is hosted. As long as the request being made to the HubSpot APIs (api.hubapi.com) is coming from a server, not the client, you should be fine.