APIs & Integrations

alphy
Member

Form API (with CORS) Documentation help

SOLVE

Hello there,
What I want to achieve: I want to call HS Form API from my front end, with a custom non-hubspot form.

https://developers.hubspot.com/docs/methods/forms/submit_form_v3 I think has poor documentation in terms of example POST.

Questions:
What is the URL for posting this data?
Where do I find the Portal ID?
Where do I find the Form ID?
What is the proper payload structure of sending data?
Do I need to make my request a query string on the URL?

Most importantly, can someone show an example of vanilla JS version of posting to Form API with CORS? Data et all please

0 Upvotes
1 Accepted solution
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Form API (with CORS) Documentation help

SOLVE

Welcome, @alphy,

Happy to help:

What is the URL for posting this data?

  • This is noted in the documentation: https://api.hsforms.com/submissions/v3/integration/submit/:portalId/:formGuid

Where do I find the portal ID?

  • This is your HubSpot account ID and can also be found in any app URL while you are logged in. For example, in https://app.hubspot.com/reports-dashboard/1234567/marketing, 1234567 is the portal ID.

Where do I find the form ID?

  • Via the Get all forms endpoint or in the URL when viewing any form in your portal.

What is the proper payload structure of sending data?

  • As documented, the payload should be formatted in JSON. All form fields should be transmitted as objects within the "fields" array.

Do I need to make my request a query string on the URL?

  • No. As documented, the submission information is contained in the body.

There's plenty of documentation out there on submitting form data with AJAX. For example, see this Stack Overflow discussion.

You can ensure that your field data is formatted correctly by following guides like this.

Isaac Takushi

Associate Certification Manager

View solution in original post

0 Upvotes
2 Replies 2
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Form API (with CORS) Documentation help

SOLVE

Welcome, @alphy,

Happy to help:

What is the URL for posting this data?

  • This is noted in the documentation: https://api.hsforms.com/submissions/v3/integration/submit/:portalId/:formGuid

Where do I find the portal ID?

  • This is your HubSpot account ID and can also be found in any app URL while you are logged in. For example, in https://app.hubspot.com/reports-dashboard/1234567/marketing, 1234567 is the portal ID.

Where do I find the form ID?

  • Via the Get all forms endpoint or in the URL when viewing any form in your portal.

What is the proper payload structure of sending data?

  • As documented, the payload should be formatted in JSON. All form fields should be transmitted as objects within the "fields" array.

Do I need to make my request a query string on the URL?

  • No. As documented, the submission information is contained in the body.

There's plenty of documentation out there on submitting form data with AJAX. For example, see this Stack Overflow discussion.

You can ensure that your field data is formatted correctly by following guides like this.

Isaac Takushi

Associate Certification Manager
0 Upvotes
ShawnMclean
Member

Form API (with CORS) Documentation help

SOLVE

What about with CORS? Do you guys support posting directly from the browser?

0 Upvotes