APIs & Integrations

Liam1
Member

Issue creating Contact Property via API

We are trying to create a custom Contact property via the API, but all our POST requests return a Bad Request 400.

The body of the response is HTML and contains the following;

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  <title>Error 400 Bad Request</title>
</head>
<body>
  <h2>HTTP ERROR 400</h2>
  <p>Problem accessing /properties/v2/contact/properties. Reason:
    <pre>    Bad Request</pre>
  </p>
</body>
</html>

Here is the request body we are trying to send, which is actually from the API documentation

{
  "name":         "newcustomproperty",
  "label":        "A New Custom Property",
  "description":  "A new property for you",
  "groupName":    "contactinformation",
  "type":         "string",
  "fieldType":    "text",
  "formField":    true,
  "displayOrder": 6,
  "options":      []
}

Not sure what to check from here. The only thing I noted was that the response from the API refers to a "v2" API url, so wondering if the request format has changed somehow?

Thanks!

0 Upvotes
2 Replies 2
cbarley
HubSpot Alumni
HubSpot Alumni

Issue creating Contact Property via API

Hi @Liam,

How are you making this request? When I copy and paste the example from the Developer Docs into Postman to test this, with a method of POST to this URL
https://api.hubapi.com/properties/v1/contacts/properties?hapikey=my_hapikey_here
I get a 200 success message and the property is created. Make sure you also have the Content-Type set to application/json as a header.

As per the docs:

Returns a 400 error with more details in the response body if there is any other 
problem with the data.

I think the v2 error listed is a red herring, as I tried submitting a POST request without the content type set to application/json, and got a 415 Unsupported Media type error very similarly formatted to the error you have above.

0 Upvotes
RahulBarpha
Participant

Issue creating Contact Property via API

Hello Team,

 

I am also facing the same issue. like below

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 415 Unsupported Media Type</title>
</head>
<body>
<h2>HTTP ERROR 415</h2>
<p>Problem accessing /properties/v2/contact/properties. Reason:

<pre> Unsupported Media Type</pre>
</p>
</body>
</html>

 

I am passing a parameter with Headers and Body like below

 

Post Method: https://api.hubapi.com/properties/v1/contacts/properties

 

Headers : 

Authorization : Bearer CMechryQLhICAQEY1eKyAyCt_t0EKMaGDTIZANrqMqrh78d0yKcRUMyZ5T4b735Q7qga8ToPAAoCQQAADIADAAgAAAABQhkA2uoyqqAVl-_Xh2P66b06grlLgXJqyRDN

Content-Type :  application/x-www-form-urlencoded

 

Body(x-www-form-urlencoded😞

 

name:R360UserRole
label:R360Role
description:This field for checking user role in R360
groupName:contactinformation
type:string
fieldType:text

 

0 Upvotes