# (400) Bad Request

**URL:** <https://community.hubspot.com/t/400-bad-request/11923>\
**Category:** APIs & Integrations\
**Tags:** contacts\
**Created:** [July 11, 2016, 9:33pm UTC](https://community.hubspot.com/t/400-bad-request/11923 "2016-07-11T21:33:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [July 11, 2016, 9:33pm UTC](https://community.hubspot.com/t/400-bad-request/11923/1 "2016-07-11T21:33:53Z")

</div>

Hi,

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):

[http://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/asmith@goobers.com/?hapikey=xxx](http://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/asmith@goobers.com/?hapikey=xxx)  
[http://api.hubapi.com/contacts/v1/contact/?hapikey=xxx](http://api.hubapi.com/contacts/v1/contact/?hapikey=xxx)

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):

“{“properties”:[{“property”:“email”,“value”:“asmith@goobers.com”},{“property”:“firstname”,“value”:“Adam”},{“property”:“lastname”,“value”:“Smith”}]}”;

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](http://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.

Thanks,  
JJ

---

<div class="post-metadata">

**Author:** ![dilloncompton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dilloncompton/32/99782_2.png) [@dilloncompton](https://community.hubspot.com/u/dilloncompton)\
**Post date:** [July 12, 2016, 2:26am UTC](https://community.hubspot.com/t/400-bad-request/11923/2 "2016-07-12T02:26:27Z")

</div>

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.

Thanks,  
Dillon

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [July 12, 2016, 2:15pm UTC](https://community.hubspot.com/t/400-bad-request/11923/3 "2016-07-12T14:15:54Z")

</div>

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.

Thanks,  
JJ

---

<div class="post-metadata">

**Author:** ![dilloncompton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dilloncompton/32/99782_2.png) [@dilloncompton](https://community.hubspot.com/u/dilloncompton)\
**Post date:** [July 12, 2016, 2:51pm UTC](https://community.hubspot.com/t/400-bad-request/11923/4 "2016-07-12T14:51:04Z")

</div>

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

//Dillon

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [August 31, 2016, 10:55pm UTC](https://community.hubspot.com/t/400-bad-request/11923/5 "2016-08-31T22:55:05Z")

</div>

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

[https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/contact-email/?hapikey=api-key](https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/contact-email/?hapikey=api-key)  
and  
[https://api.hubapi.com/contacts/v1/contact/vid/contact-id/profile?hapikey=api-key](https://api.hubapi.com/contacts/v1/contact/vid/contact-id/profile?hapikey=api-key)

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.

Thanks  
L

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [August 31, 2016, 11:16pm UTC](https://community.hubspot.com/t/400-bad-request/11923/6 "2016-08-31T23:16:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 7, 2016, 6:35am UTC](https://community.hubspot.com/t/400-bad-request/11923/7 "2016-09-07T06:35:30Z")

</div>

Well, now I would really much appreciate a C# example that is actually working  
 ![slightly_smiling_face.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/4/2/42c4d129a1c6aa74d89f3066ee8fbb15db46b3b5.png)

Kind regards,  
Henrik

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 7, 2016, 2:33pm UTC](https://community.hubspot.com/t/400-bad-request/11923/8 "2016-09-07T14:33:30Z")

</div>

Hi Henrik,

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

Good Luck,  
JJ

==========================================================================

```auto
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"), "\"},",
 "{\"property\":\"lifecyclestage\",\"value\":\"lead\"}]}");

 using (var requestWriter = new StreamWriter(webRequest.GetRequestStream()))
 {
 requestWriter.Write(json);
 }

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

 return responseText;
}

```

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 20, 2016, 7:08am UTC](https://community.hubspot.com/t/400-bad-request/11923/9 "2016-09-20T07:08:07Z")

</div>

Thanx, that worked perfectly!

Now I’m having trouble getting the contact via the api:  
[https://api.hubapi.com/contacts/v1/contact/email/qwerty@qwerty.dk/profile?hapikey=MyKey](https://api.hubapi.com/contacts/v1/contact/email/qwerty@qwerty.dk/profile?hapikey=MyKey)

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  
 ![slightly_smiling_face.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/4/2/42c4d129a1c6aa74d89f3066ee8fbb15db46b3b5.png)

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 20, 2016, 10:10pm UTC](https://community.hubspot.com/t/400-bad-request/11923/10 "2016-09-20T22:10:00Z")

</div>

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?

Thanks,  
JJ

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [February 12, 2017, 4:47pm UTC](https://community.hubspot.com/t/400-bad-request/11923/11 "2017-02-12T16:47:25Z")

</div>

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?
