APIs & Integrations

martuanez
Member

Create Contact post request fails when email is present or custom fields are added

SOLVE

Create Contact post request fails when email is present or custom fields are added.

It's worth notting that using an email does not work when using axios on nodeJS but it does work with Postman

With the following data the contact is created:

{
    properties: [
      {
        property: 'firstname',
        value: 'firstname',
      },
      {
        property: 'lastname',
        value: 'lastname',
      },
      {
        property: 'phone',
        value: 'phone',
      }
    ]
  }


If email is added it fails with status error 409:

{
    properties: [
      {
        property: 'firstname',
        value: 'firstname',
      },
      {
        property: 'lastname',
        value: 'lastname',
      },
      {
        property: 'email',
        value: 'valid@email.co',
      },
      {
        property: 'phone',
        value: 'phone',
      }
    ]
  }

If custom property is added the the status error is 400:

{
    properties: [
      {
        property: 'firstname',
        value: 'firstname',
      },
      {
        property: 'lastname',
        value: 'lastname',
      },
      {
        property: 'labels',
        value: ['label1'],
      },
      {
        property: 'phone',
        value: 'phone',
      }
    ]
  }


 

0 Upvotes
1 Accepted solution
WendyGoh
Solution
HubSpot Employee
HubSpot Employee

Create Contact post request fails when email is present or custom fields are added

SOLVE

Hi @martuanez,

 

Let's go through the question one by one here:

 

1. As stated in the Create a new contact API documentation, the reason why you are seeing a status error 409 after adding an email is because,

 

There is an existing contact with the email address included in the request. The response body will include the identityProfile details of the contact, which will include the vid of the existing record.

 

You can try using a different email that doesn't exist within your portal and see if all is well.

 

2. When looking at the POST body which contain the custom property, I noticed that the value for the label custom property has [ ] which is likely why you're seeing a 400 error as it is an invalid JSON (You can check the JSON validity here: https://jsonformatter.curiousconcept.com/).

 

Remove the [ ] and it should work just fine.

View solution in original post

0 Upvotes
3 Replies 3
WendyGoh
Solution
HubSpot Employee
HubSpot Employee

Create Contact post request fails when email is present or custom fields are added

SOLVE

Hi @martuanez,

 

Let's go through the question one by one here:

 

1. As stated in the Create a new contact API documentation, the reason why you are seeing a status error 409 after adding an email is because,

 

There is an existing contact with the email address included in the request. The response body will include the identityProfile details of the contact, which will include the vid of the existing record.

 

You can try using a different email that doesn't exist within your portal and see if all is well.

 

2. When looking at the POST body which contain the custom property, I noticed that the value for the label custom property has [ ] which is likely why you're seeing a 400 error as it is an invalid JSON (You can check the JSON validity here: https://jsonformatter.curiousconcept.com/).

 

Remove the [ ] and it should work just fine.

0 Upvotes
martuanez
Member

Create Contact post request fails when email is present or custom fields are added

SOLVE

@WendyGoh

I've deleted all contacts, created ridiculous & creative email addresses to prevent having it repeated and still have the same issue.

With all contacts deleted, meaning having no contacts at all, if I make the request with axios the 409 error comes in the response, but, here the interesting part, the contact is created despite the error, so I end up with one contact that has been created but an error in the response, sounds like a bug to me.

0 Upvotes
martuanez
Member

Create Contact post request fails when email is present or custom fields are added

SOLVE

The 409 was happening because of having another server instance in other place

0 Upvotes