(400) Bad Request



I’ve been trying to add a contact to HubSpot via my test portal from some .NET code on my development server using one of the two following APIs (where xxx is the API key I was assigned last week):


Additionally, the following attributes have been assigned to my webRequest:

webRequest.Method = “POST”;
webRequest.ContentType = “application/json”;

I’ve tried passing the JSON to HubSpot as a serialized string like so (prior to serialization):


However, testing has resulted in the following response: The remote server returned an error: (400) Bad Request.

Thinking that perhaps the above string was JSON-format challenged, I tested it at JSONLint.com where it came back as valid JSON. I therefore am finding myself at a loss for where I’m going astray and would be most appreciative of any assistance you could provide.



Hi JJ,
Nothing looks immediately wrong in your JSON to me, but there are several things I can think of that might be going on. Most likely this is an encoding/serialization issue of some sort.

I’m not super familiar with .NET, but if you can log the exact request you are sending and the full response you are getting back from HubSpot, I can try to give you a better idea of what the error is.



Hi Dillon,

Thanks for the reply. Upon stepping through the code with some fresh eyes and making some minor adjustments, I was able to garner a response from HubSpot and get my contact added. Seems the third-party online example I found for making a JSON call in .NET, while directionally accurate, was an incomplete solution.



Glad you got it sorted! Let us know if you have any other questions.



Please can you share you solution? I’m having a similar problem in C# updating a contact. I’ve tried these endpoints and neither works


and here is my JSOM sample data

“{‘properties’: [{‘property’:‘email’,‘value’:‘a@b.com’},{‘property’: ‘firstname’,‘value’: ‘Carmen’},{‘property’: ‘lastname’,‘value’: ‘San Diego’},{‘property’: ‘lifecyclestage’,‘value’: ‘customer’}]}”

I keep getting 400 Bad request.



Never mind I found the solution to my problem. I changed single quotes( ’ ) to (") in the JSON string and it worked fine.


Well, now I would really much appreciate a C# example that is actually working :slight_smile:

Kind regards,


Hi Henrik,

Here’s the code I used to get the desired result.

Good Luck,


public static string UploadHubSpotContact(DataTable dt)
  var contactEmail = dt.Rows[0].Field<string>("Email");
  var hubSpotApiKey = ConfigurationManager.AppSettings["HubSpotApiKey"];
  var hubSpotRestApi = string.Concat("http://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/", contactEmail, "/?hapikey=", hubSpotApiKey);
  var responseText = "";
  var webRequest = WebRequest.Create(new Uri(hubSpotRestApi)) as HttpWebRequest;

  if (webRequest != null)
    webRequest.Method = "POST";
    webRequest.ContentType = "application/json";
    var json = string.Concat("{\"properties\":[",
      "{\"property\":\"email\",\"value\":\"", contactEmail, "\"},",
      "{\"property\":\"firstname\",\"value\":\"", dt.Rows[0].Field<string>("FirstName"), "\"},",
      "{\"property\":\"lastname\",\"value\":\"", dt.Rows[0].Field<string>("LastName"), "\"},",
      "{\"property\":\"company\",\"value\":\"", dt.Rows[0].Field<string>("Company"), "\"},",
      "{\"property\":\"jobtitle\",\"value\":\"", dt.Rows[0].Field<string>("Title"), "\"},",
      "{\"property\":\"phone\",\"value\":\"", dt.Rows[0].Field<string>("Phone"), "\"},",

    using (var requestWriter = new StreamWriter(webRequest.GetRequestStream()))

    var response = webRequest.GetResponse();
    using (var reader = new StreamReader(response.GetResponseStream()))
      responseText = reader.ReadToEnd();

  return responseText;


Thanx, that worked perfectly!

Now I’m having trouble getting the contact via the api:

In Fiddler and a browser it works perfect and I’m getting a perfectly formatted JSon in return.- But from my C# code I get a 404 error even though it’s the exact same url I’m sending via a WebRequest (GET).

Any help would be appreciated :slight_smile:


Hi Henrik,

I was able to garner a result using a simplified version of the code I posted earlier, substituting the APIs and changing the method to a GET. Could you please post your code for review?



I am getting a similar error with some contact properties I am trying to update. The properties that fail appear to have a list of values in HS and the value I am sending in not in the list.
Is there a way to disable the value checking via the API?