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/\/<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\”,\“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.