Submit Form API with Ruby on Rails - Response 204 but no content


I'm having an issue with the submit form API (

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 = "{ENV['hubspot_portal_id']}/#{ENV['hubspot_enquiry_form_GUID']}"

        uri = URI.parse(@endpoint)
        header = header = {'Content-Type': 'application/x-www-form-urlencoded'}
        http =, uri.port)
        http.use_ssl = true
	    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
        request =, header)
        request.body = payload.to_json
        response = http.request(request)
        response_output = "response #{response.body}"
    rescue => e
        response_output = "failed: #{e}"

Here is the header and body of my request:

  - application/x-www-form-urlencoded
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
  - "*/*"
  - Ruby
  - close
  - '276'
  - application/x-www-form-urlencoded
body: '{"email":"","firstname":"Test","lastname":"Test","venue":"testing","product_type":"test","hs_context":{"hutk":"d68c5983a0f224a8c87f113856466184","ipAddress":"","pageUrl":"http://localhost:3000/enquiry","pageName":"EnquiryForm"}}'

I'm at a bit of a loss on what to change. Any suggestions?


Hi @GaryElliott,

Can you send me a link to the form you're referring to in HubSpot so that I can take a closer look? Also, I'm not particularly familiar with Ruby; are the form fields (email, firstname, etc.) being put into a JSON object? They should be URI encoded fields, since the endpoint doesn't accept JSON.


Hi Derek,

I’m currently using a sandbox to test.

Here’s the form.

And yes, all values in the payload are URI encoded. This includes form values as well as those set in hs_context


Solved it.

Turns out, the whole payload doesn't need to be JSON.

This is what worked:

hs_context = { hutk: cookies[:hubspotutk],
                              ipAddress: request.remote_ip,
                              pageUrl: request.url,
                              pageName: "EnquiryForm" 

 payload = URI.escape("email=#{params[:email]}&firstname=#{params[:first_name]}&lastname=#{params[:last_name]}&venue=#{params[:venue]}&product_type=#{params[:product_type]}&hs_context=#{hs_context}")