APIs & Integrations

FilipeFerreira
Member

CORS In get all deals api endpoint

Hi,

I was trying to setup a http get request to the

https://api.hubapi.com/deals/v1/deal/paged?hapikey=<API_KEY>&includeAssociations=true&limit=250&properties=dealname

endpoint and I am able to do so on the browser and with curl, but when I try doing it using Angular2 http client and I get the following error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.hubapi.com/deals/v1/deal/paged?hapikey=<API_KEY>&includeAssociations=true&limit=250&properties=dealname. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

could some one help me with this? Not sure what I am doing wrong.

0 Upvotes
7 Replies 7
stefenphelps
Member | Partner
Member | Partner

CORS In get all deals api endpoint

I wrote a post about a simple way to enable CORS for any HubSpot api if anyone is still struggling with this.

The basic idea is you use PHP to make the server side request, then you can enable CORS on your server and make all the AJAX requests that you need. It only takes a couple lines of PHP so it's pretty simple to do.

0 Upvotes
npuli
Member

CORS In get all deals api endpoint

hi,
I would like to get blog details of your website through ajax call but I am getting "Uncaught SyntaxError: Unexpected identifier" please address it as soon as possible.
$.ajax({
type:“GET”,
dataType: “jsonp”,
jsonpCallback:‘callback’,
contentType:“application/json”,
url:"https://api.hubapi.com/content/api/v2/blog-posts/"+5067937629+"?hapikey=**********"
success: function (data) {} });

0 Upvotes
FilipeFerreira
Member

CORS In get all deals api endpoint

@dadams Thank you for the help, yes I am already using a nodejs server so will try an make the calls on the backend, do you know if in the future Ajax requests will be allowed?

0 Upvotes
Dadams
HubSpot Employee
HubSpot Employee

CORS In get all deals api endpoint

It’s something we’ll likely take another look at next year, but even if we do start supporting this it’s unlikely CORS would be supported for requests using hapikeys, as exposing that key to a client poses a considerable security risk.

0 Upvotes
FilipeFerreira
Member

CORS In get all deals api endpoint

Would I have to use a node server to get the data and pass it on to the angular2 app?

0 Upvotes
Dadams
HubSpot Employee
HubSpot Employee

CORS In get all deals api endpoint

If you’re already running a node server, then yes that server could get the data and pass it to the angular app.

0 Upvotes
Dadams
HubSpot Employee
HubSpot Employee

CORS In get all deals api endpoint

Hi @FilipeFerreira

Our APIs do not support cross-origin AJAX requests, since that could expose your API key to anyone viewing that page. You’ll need to make the AJAX request to your server, which would then add the api key to the request URL and make the request to the HubSpot API server-side.

Do HubSpot APIs support CORS / AJAX requests?

At this time, HubSpot APIs do not support support cross-origin (CORS) AJAX requests. In order to use AJAX, you would need to make the request to an external proxy server that could then make requests to HubSpot's APIs.

0 Upvotes