How do I build an end point for an Ajax call in HubSpot COS?




Can’t figure out how to build an endpoint for my AJAX in the HubSpot COS… any suggestions appreciated.

Here’s what I’ve done:

  1. Created a new app with a HTML/JavaScript Quiz which is used in our HubSpot COS site.

  2. When the visitor completes the the quiz the data is pushed to custom properties in their contact record (if they complete the form to become a contact).

  3. Everything was working fine using the HubSpot API Keys (it’s only for our site).

When the site went live last night (using https) all the API Calls fail with the following error:

XMLHttpRequest cannot load No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘’ is therefore not allowed access.

From research online I need to build an endpoint for the AJAX call… the problem is I haven’t been able to figure out how to create an endpoint inside the HubSpot COS.

Any help appreciated.

Thank you

p.s. posted as a new question just in case it’s useful for someone else.

p.p.s. loads of useful stuff on for PHP users.


@Webalite is the app you created hosted on HubSpot or somewhere else? Where is the Quiz? You don’t have server-side access on HubSpot to create an endpoint. The error you received is because you made a cross-domain request to our servers. Those requests need to be made server-side and not client-side.


Good morning Peter

The Quiz is client side only (JavaScript/JQuery) and is loaded on the homepage in my (entirely) HubSpot COS site.

Some of the more complex operations (for version 2) will require more intensive API calls (e.g. Timeline). Some of the API calls are unavailable unavailable in the templates through HubL.

Really keen for suggestions on how I’d call the API if my entire site is in the HubSpot COS?

I can set up another server to handle the Ajax queries but it seems – in my opinion – to defeat the purpose of using HubSpot COS. Trying to do things the proper way (no hacks) because there’s a few HubSpot Apps in my head that I need to code… so getting “My First App” right is a good test.

Really appreciate your input.

Thank you


@Webalite To hit certain endpoints that are not in the Contact API like the Timeline for ex. This will have to be done using server-side code so you will have to use your second option of spinning up a server to handle the AJAX calls and then forward it along back to HubSpot. I agree this isn’t what I would call ideal but at the moment the COS does not have the ability to make server-side requests.


Thank you @pmanca

That is utterly ridiculous that the HubSpot COS can’t access it’s own APIs.

Ripped out all the API code to make the quiz work – what a complete waste of my time.

I will create a blog post to warn others of the failing of HubSpot COS APIs.

Thanks again for your help.


Hello anyone else that’s looking for some answers.

I’ve opened a Feature Request on HubSpot Ideas: