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

**URL:** <https://community.hubspot.com/t/submit-form-api-with-ruby-on-rails-response-204-but-no-content/12015>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [April 17, 2018, 3:47pm UTC](https://community.hubspot.com/t/submit-form-api-with-ruby-on-rails-response-204-but-no-content/12015 "2018-04-17T15:47:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GaryElliott](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/garyelliott/32/52876_2.png) [@GaryElliott](https://community.hubspot.com/u/GaryElliott)\
**Post date:** [April 17, 2018, 3:47pm UTC](https://community.hubspot.com/t/submit-form-api-with-ruby-on-rails-response-204-but-no-content/12015/1 "2018-04-17T15:47:36Z")

</div>

I’m having an issue with the submit form API ([https://developers.hubspot.com/docs/methods/forms/submit\_form](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:

```auto
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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![Derek\_Gervais](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/derek_gervais/32/17429_2.png) [@Derek\_Gervais](https://community.hubspot.com/u/Derek_Gervais)\
**Post date:** [April 19, 2018, 2:05pm UTC](https://community.hubspot.com/t/submit-form-api-with-ruby-on-rails-response-204-but-no-content/12015/2 "2018-04-19T14:05:38Z")

</div>

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.

![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/d/d/ddbc057cffe7fc20edaf0008674d3b943101f61a.png) [developers.hubspot.com](https://developers.hubspot.com/docs/methods/forms/submit_form)

### [Submit data to a form | HubSpot Forms API](https://developers.hubspot.com/docs/methods/forms/submit_form)

POST [https://forms.hubspot.com/uploads/form/v2/:portal\_id/:form\_guid](https://forms.hubspot.com/uploads/form/v2/:portal%5C_id/:form%5C_guid) - Send form submission data to HubSpot. Form submissions from external sources can be made to any registered HubSpot form. You can see a list of forms on your portal by going to…

---

<div class="post-metadata">

**Author:** ![GaryElliott](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/garyelliott/32/52876_2.png) [@GaryElliott](https://community.hubspot.com/u/GaryElliott)\
**Post date:** [April 19, 2018, 2:18pm UTC](https://community.hubspot.com/t/submit-form-api-with-ruby-on-rails-response-204-but-no-content/12015/3 "2018-04-19T14:18:56Z")

</div>

Hi Derek,

I’m currently using a sandbox to test.

Here’s the form.

> **[Forms | HubSpot](https://app.hubspot.com/forms/4152608/663a2fc2-8f53-457e-a622-9d05aa1911e7/submissions)**

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

---

<div class="post-metadata">

**Author:** ![GaryElliott](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/garyelliott/32/52876_2.png) [@GaryElliott](https://community.hubspot.com/u/GaryElliott)\
**Post date:** [April 20, 2018, 8:31pm UTC](https://community.hubspot.com/t/submit-form-api-with-ruby-on-rails-response-204-but-no-content/12015/4 "2018-04-20T20:31:19Z")

</div>

Solved it.

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

This is what worked:

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

 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}")

```
