APIs & Integrations

sebastianrb
Member

Submitting form data to HubSpot

Hey everyone,

I’m new to Hubspot and have a question about submitting and saving form data from my website. I am currently building a React.js application that includes a simple contact form asking for a user’s name and email address. When a user submits the form, I want to use AJAX to send and save the user info from the form to my Hubspot portal (I am using the free tools, which might affect the features I’m able to access?). Basically I’m looking to create a new contact/record from the data.

I tried reading over the documentation, but it lacks useful examples and overall I didn’t find the information very helpful or clear. Could somebody walk me through the steps necessary to submit data via a front-end form and save it to HubSpot? Specifically, if I have a JavaScript JSON object of form data, how might I submit that data to HubSpot using AJAX? Or is there some better way to do it?

Many thanks,
Sebastian

0 Upvotes
1 Reply 1
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Submitting form data to HubSpot

HI @sebastianrb,

You’re correct, the issue here is that Marketing Free portals do not have access to the API, so for that specific portal no marketing scopes would be supported. Additionally, the HubSpot APIs do not support CORS / AJAX requests as this would expose any authentication you’re using for the request. The following document has some more information on this:

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.

For a portal with access to the marketing APIs, you could use the Submit form data endpoint to pass your form submission into HubSpot (see below). This would update/create contacts in HubSpot, and the document includes some examples in various languages (PHP, C#, Node JS, etc.)

Submit data to a form | HubSpot Forms API

POST https://forms.hubspot.com/uploads/form/v2/:portal_id/:form_guid - Send form submission data to HubSpot. Form submissions from external sources can be made to any registered HubSpot form. You can see a list of forms on your portal by going to...

0 Upvotes