Trouble with endpoint


#1

Hi,

I'm trying to send an HTTP Post to a HubSpot form, but I'm not getting a post response back.
The endpoint url I was using was https://forms.hsforms.com/submissions/v3/public/submit/formsnext/multipart/3975608/7aad3a80-8974-4182-b408-e2f0dd124138, which I found in the form's code under form action=...

On your Submit Data To A Form via Ajax page it looks like the endpoint should instead use this structure: https://api.hsforms.com/submissions/v3/integration/submit/:portalId/:formGuid. Can you clarify which I should be using?

Please help!

Thanks,
Matt


#2

Here's the form URL by the way - https://share.hsforms.com/1eq06gIl0QYK0COLw3RJBOA2d7lk


#4

Hi @Matt9,

To submit a form with AJAX, you should use the https://api.hsforms.com/submissions/v3/integration/submit/:portalId/:formGuid endpoint, as outlined here.

I'm curious, though, can you point me to the page where you found the formsnext/multipart URL?


#5

@Isaac_Takushi Ahh ok!

Can you confirm that the Content Type should be application/json?

I found the /formsnext/multipart URL in the code for this form - https://share.hsforms.com/1eq06gIl0QYK0COLw3RJBOA2d7lk. It appeared that the form was posting to that URL, so that's what I tried using.

Also, just to be clear, would either the v2 or v3 endpoints work for the same form (assuming I'm not using Ajax)? Or is there a setting with the form that dictates which endpoint is able to be used? Sorry, I'm new to a lot of this!


#6

Good to know, @Matt9! It seems the "public" form URL uses a different endpoint. For your purposes, you should use the URLs specified in our developer documentation.

Yes, I can confirm the v3 endpoint uses the Content-Type application/json. The v2 endpoint, on the other hand, uses application/x-www-form-urlencoded.

Finally, yes, either the v2 or v3 endpoints will work for the same form. Only the v3 endpoint accepts AJAX (CORS) requests, though.


#7

Thanks @Isaac_Takushi.

I just tried putting a test post through to the v3 endpoint for a different form and received the following error: {"status":"error","message":"Invalid input JSON on line 1, column 11: Unrecognized token 'firstname': was expecting 'null', 'true', 'false' or NaN","correlationId":"a0335b16-37eb-4f2d-ba61-65aeece38634","requestId":"59484d5d6ece893b3c0cdb2d3450c44a"}. The first parameter I was trying to post was firstname=John.

Any idea what the problem is?


#8

Hi @Matt9,

That error generally denotes a syntactical error. Would you share the full payload you attempted to send?


#9

@Isaac_Takushi

I'm trying to send the post through from a lead management platform called LeadsPedia. Here's the post info:

Post Request

Request URL:
https://api.hsforms.com/submissions/v3/integration/submit/3975608/7aad3a80-8974-4182-b408-e2f0dd124138

Post Parameters:
firstname=John&lastname=Smith&jobtitle=Marketing&company=Better Buys&email=jsmith@test.com&phone=123-123-1234&in_market=Yes&most_important_feature=Price&buying_timeframe2=Within 6 Months&asset_name=Top 15 Report&country=&company_size=250&sic_code=1234&industry=Media

Post Response
{"status":"error","message":"Invalid input JSON on line 1, column 11: Unrecognized token 'firstname': was expecting 'null', 'true', 'false' or NaN","correlationId":"a0335b16-37eb-4f2d-ba61-65aeece38634","requestId":"59484d5d6ece893b3c0cdb2d3450c44a"}

Does that give you any insight?


#10

Hi @Matt9,

Sincere apologies for the delayed response. Somehow your message fell through the cracks.

You are receiving that error because your post body is formatted as a query string instead of JSON. The v2 Forms API endpoint accepts that format, but you'll need to use a JSON-formatted body for the v3 endpoint.

Instead of:

firstname=John&lastname=Smith&email=jsmith@test.com

Use:

{
  "fields": [
    {
      "name": "email",
      "value": "jsmith@test.com"
    },
    {
      "name": "lastname",
      "value": "Smith"
    },
    {
      "name":"firstname",
      "value":"John"
    }
  ]
}