# Forms API 400 bad request with C# HttpRequest

**URL:** <https://community.hubspot.com/t/forms-api-400-bad-request-with-c-httprequest/38385>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [June 3, 2021, 10:16pm UTC](https://community.hubspot.com/t/forms-api-400-bad-request-with-c-httprequest/38385 "2021-06-03T22:16:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DMcLellan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dmclellan/32/59606_2.png) [@DMcLellan](https://community.hubspot.com/u/DMcLellan)\
**Post date:** [June 3, 2021, 10:16pm UTC](https://community.hubspot.com/t/forms-api-400-bad-request-with-c-httprequest/38385/1 "2021-06-03T22:16:41Z")

</div>

Hi there,

I’m new to using HubSpot, and am having trouble getting a successful POST to the API server.

I have setup an HttpRequest which sends some JSON data to the Forms API based on the example information in the API docs.

My request URL: [https://api.hsforms.com/submissions/v3/integration/secure/submit/\](https://api.hsforms.com/submissions/v3/integration/secure/submit/%5C)/\<formid\>?hapikey=

The JSON string I am sending is formatted like so:

“{\“submittedAt\”:\“637583940787178861\”,\“fields\”:{\“home\_club\”:\“test\”,\“firstname\”:\“test\”,\“lastname\”:\“qweqw\”,\“date\_of\_birth\_datepicker\_\_\_YYYY\”:\“1985\”,\“date\_of\_birth\_datepicker\_\_\_MM\”:\“01\”,\“date\_of\_birth\_datepicker\_\_\_DD\”:\“02\”,\“membership\_number\”:\“12345\”,\“mobilephone\”:\“0123456789\”,\“email\”:\“[test@test.com](mailto:test@test.com)\”,\“cancellation\_date\_\_YYYY\”:\“2021\”,\“cancellation\_date\_\_MM\”:\“08\”,\“cancellation\_date\_\_DD\”:\“09\”,\“reason\_for\_cancellation\”:\“Medical\”,\“cancellation\_terms\_\_\_conditions\”:\“on\”}}”

I copied the field names from an embedded form that matches the formId, but for other reasons, I need to post this data using the API and not using the HubSpot embedded form.

Below is my C# reference code:

var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);  
httpWebRequest.ContentType = “application/json”;  
httpWebRequest.Method = “POST”;

var fields = new Dictionary\<string, string\>();  
fields.Add(…);

string json = JsonConvert.SerializeObject(new  
{  
submittedAt = new DateHelper().GetCurrentNZTime().Ticks.ToString(),  
fields = fields  
}) ;

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))  
{  
streamWriter.Write(json);  
}

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();  
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))  
{  
var result = streamReader.ReadToEnd();  
}

The response is coming back as 400 - Bad Request. HubSpot support has asked me to look here for help.

Thank you.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [June 4, 2021, 2:42pm UTC](https://community.hubspot.com/t/forms-api-400-bad-request-with-c-httprequest/38385/2 "2021-06-04T14:42:58Z")

</div>

Hey @DMcLellan

That timestamp for **submittedAt** looks suspicious

Should be in milliseconds and can only be used to backdate a submission.

I would consider removing it from you body and see if that works. If it does and you need it, you will want to make sure that it is in milliseconds

---

<div class="post-metadata">

**Author:** ![DMcLellan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dmclellan/32/59606_2.png) [@DMcLellan](https://community.hubspot.com/u/DMcLellan)\
**Post date:** [June 5, 2021, 2:58am UTC](https://community.hubspot.com/t/forms-api-400-bad-request-with-c-httprequest/38385/3 "2021-06-05T02:58:58Z")

</div>

Hi @dennisedson and thanks for the reply.

I have also been working with support on this and they too identified that the milliseconds portion of my data was incorrect.

I have modified my json string and now have the correct formatting. Below is the new formatting which is still giving me a 400 - Bad Request.

This is the string after JSON.stringify:

“{\“submittedAt\”:\“1622859625723\”,\“fields\”:[{\“name\”:\“home\”,\“value\”:\“test\”},{\“name\”:\“firstname\”,\“value\”:\“test\”},{\“name\”:\“lastname\”,\“value\”:\“qweqw\”},{\“name\”:\“date\_of\_birth\_datepicker\_\”,\“value\”:\“473490000000\”},{\“name\”:\“membership\_number\”,\“value\”:\“12345\”},{\“name\”:\“mobilephone\”,\“value\”:\“0123456789\”},{\“name\”:\“email\”,\“value\”:\“[test@test.com](mailto:test@test.com)\”},{\“name\”:\“cancellation\_date\”,\“value\”:\“1628481600000\”},{\“name\”:\“cancellation\_terms\_\_\_conditions\”,\“value\”:\“true\”}]}”

Any more thoughts on this?

Thank you very much.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [June 7, 2021, 2:53pm UTC](https://community.hubspot.com/t/forms-api-400-bad-request-with-c-httprequest/38385/4 "2021-06-07T14:53:11Z")

</div>

@DMcLellan

Was that date in the past when you submitted it?

Can you try backdating atlease 24hrs as well as attempting to submit without that date altogether?

---

<div class="post-metadata">

**Author:** ![DMcLellan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dmclellan/32/59606_2.png) [@DMcLellan](https://community.hubspot.com/u/DMcLellan)\
**Post date:** [June 8, 2021, 9:28pm UTC](https://community.hubspot.com/t/forms-api-400-bad-request-with-c-httprequest/38385/5 "2021-06-08T21:28:42Z")

</div>

Hi again @dennisedson and thanks for the reply.

As it turned out through digging through the API docs. When submitting a post to the Forms API, the email field must validate to a real email address. I was testing submissions using [test@test.com](mailto:test@test.com) and originally [example@example.com](mailto:example@example.com) since this is what HubSpot has listed in the docs as example JSON data. It’s a bit contradictory, but that turned out to be the issue.

I appreciate your help, though.

This post can be archived and considered resolved.
