APIs & Integrations

sa01
Member

Getting a "400 Bad Request" when trying to add a contact

I can’t figure out what I’m doing wrong here because there are no details in the response. Anyone got any ideas?

Request URL:

https://api.hubapi.com/contacts/v1/contact/?hapikey=apikey

My headers:

request.Method = “POST”;
request.ContentType = “application/json”;
request.ContentLength = data.Length;

And my JSON:

{
“properties”:[
{
“property”:“lead_source”,
“value”:“hubspot”
},
{
“property”:“location”,
“value”:“contact location”
},
{
“property”:“firstname”,
“value”:“TEST”
},
{
“property”:“lastname”,
“value”:“TEST”
},
{
“property”:“email”,
“value”:"test@test.com"
},
{
“property”:“phone”,
“value”:“999 999 9999”
},
{
“property”:“custom_field_1”,
“value”:“Yes”
},
{
“property”:“custom_field_2”,
“value”:“Yes”
},
{
“property”:“custom_field_3”,
“value”:“one;two;three”
},
{
“property”:“custom_field_4”,
“value”:“one;two”
},
{
“property”:“custom_field_5”,
“value”:“3”
}
]
}

And lastly, I don’t know if this is necessary, but I’ll also post the C# code I’m using to make the request:

       Contact c = CreateContact(p);
       var request = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["HubSpotSvcUrl"]);
       var postData = JsonConvert.SerializeObject(c);
       var data = Encoding.UTF8.GetBytes(postData);
       request.Method = "POST";
       request.ContentType = "application/json";
       request.ContentLength = data.Length;
       using (var stream = request.GetRequestStream())
       {
           stream.Write(data, 0, data.Length);
       }
       var response = (HttpWebResponse)request.GetResponse();
0 Upvotes
1 Reply 1
sa01
Member

Getting a "400 Bad Request" when trying to add a contact

I was using the wrong API key.