I’m having an issue with the submit form API (https://developers.hubspot.com/docs/methods/forms/submit_form).
I’m getting a 204 response. But there is a message with ‘No content’. The form is getting submissions but they are all ‘No Contact Record’.
Here is the code from my controller:
payload = { email: params[:email],
firstname: params[:first_name],
lastname: params[:last_name],
venue: params[:venue],
product_type: params[:product_type],
hs_context: { hutk: cookies[:hubspotutk],
ipAddress: request.remote_ip,
pageUrl: request.url,
pageName: "EnquiryForm" }
}
endpoint = "https://forms.hubspot.com/uploads/form/v2/#{ENV['hubspot_portal_id']}/#{ENV['hubspot_enquiry_form_GUID']}"
begin
uri = URI.parse(@endpoint)
header = header = {'Content-Type': 'application/x-www-form-urlencoded'}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri, header)
request.body = payload.to_json
response = http.request(request)
response_output = "response #{response.body}"
rescue => e
response_output = "failed: #{e}"
end
Here is the header and body of my request:
header:
:content-type:
- application/x-www-form-urlencoded
accept-encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
accept:
- "*/*"
user-agent:
- Ruby
connection:
- close
host:
- forms.hubspot.com
content-length:
- '276'
content-type:
- application/x-www-form-urlencoded
body: '{"email":"test@test.com","firstname":"Test","lastname":"Test","venue":"testing","product_type":"test","hs_context":{"hutk":"d68c5983a0f224a8c87f113856466184","ipAddress":"127.0.0.1","pageUrl":"http://localhost:3000/enquiry","pageName":"EnquiryForm"}}'
body_stream:
body_data:
I’m at a bit of a loss on what to change. Any suggestions?