APIs & Integrations

ablayze_jb
Participant

Can't send POST data to hubspot form api using client side

SOLVE

Screen Shot 2022-05-12 at 2.36.08 PM.png

Above is my code for sending form data to hubspot forms. Any idea what is the proper way to send form data to hubspot forms using client side?

0 Upvotes
1 Accepted solution
miljkovicmisa
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Can't send POST data to hubspot form api using client side

SOLVE

Hello @ablayze_jb . Thanks for writing. Seems like the data you send is malformed, your formStepOne variable should contain a JSON object that has the name and value for the field, where the name is the actual field name and value its value you get from the form. It should look something like the following:

 

 

 

var formStepOne = {
    "fields": [
      {
        "name": "firstname",
        "value": ...
      },
      {
        "name": "lastname",
        "value": ...
      },
      ...
    ]
  }

 

 

 

 Change or add the following : contentType : 'application/json', dataType : 'json',
Also add the headers: {"Content-Type" : "application/json"} setting.
Hope this helps, let us know how it went and if you need more help!
Also make sure to post the errors if you get any so it helps with debugging.

Cheers!

If my answer was helpful please mark it as a solution.

View solution in original post

4 Replies 4
miljkovicmisa
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Can't send POST data to hubspot form api using client side

SOLVE

Hello @ablayze_jb . Thanks for writing. Seems like the data you send is malformed, your formStepOne variable should contain a JSON object that has the name and value for the field, where the name is the actual field name and value its value you get from the form. It should look something like the following:

 

 

 

var formStepOne = {
    "fields": [
      {
        "name": "firstname",
        "value": ...
      },
      {
        "name": "lastname",
        "value": ...
      },
      ...
    ]
  }

 

 

 

 Change or add the following : contentType : 'application/json', dataType : 'json',
Also add the headers: {"Content-Type" : "application/json"} setting.
Hope this helps, let us know how it went and if you need more help!
Also make sure to post the errors if you get any so it helps with debugging.

Cheers!

If my answer was helpful please mark it as a solution.

ablayze_jb
Participant

Can't send POST data to hubspot form api using client side

SOLVE

Here's my code but i still get an error

Screen Shot 2022-05-13 at 10.09.32 PM.png

 

and for ajax on client side

Screen Shot 2022-05-13 at 10.09.47 PM.png

 

and im getting this error
Screen Shot 2022-05-13 at 10.14.40 PM.png

0 Upvotes
miljkovicmisa
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Can't send POST data to hubspot form api using client side

SOLVE

Why does the error show a "GET" request? Isn't the "POST" request the issue here?

0 Upvotes
ablayze_jb
Participant

Can't send POST data to hubspot form api using client side

SOLVE

Its already working. i just noticed 

its
method: "POST" (This one works for old version of jquery)

should be
type: "POST" (For new version of jquery)

0 Upvotes