When we are tried to create a Company. Thrown an exception "BadRequest"


#1

Hi All,

When we are tried to create a Company. Thrown an exception "BadRequest".

Passing value below:

var client = new RestClient("https://api.hubapi.com/");

var request = new RestRequest("companies/v2/companies?hapikey=" + hapiKey, Method.POST);

request.RequestFormat = DataFormat.Json;

request.AddBody(new
{
properties = new[] {
new { property = "name", value = "Test2"},
new { property = "domain", value = "test2.com"},
new { property = "description", value = "Test Company description"},
new { property = "hubspot_owner_id", value = accountOwner}
}
});

IRestResponse response = client.Execute(request);

if (Convert.ToString(response.StatusCode) == "OK")
{
string data = response.Content;

JObject jObject = JObject.Parse(data);
Data datas = JsonConvert.DeserializeObject<Data>(jObject.ToString());

return datas.vid.ToString();

}
else
return response.StatusCode.ToString();

Please help me to give the proper solutions.

Thanks!
Surajit


#3

Hi @surajit.ghosh,

Can you give me the raw error message & status code you're getting from HubSpot?