APIs & Integrations

NSaad
Member

Here's how to create a note on a contact through the API.

I spent hours fighting through this poorly designed API that HubSpot "convieniently" doesn't let you have access to support for its usage. To help you get your note added without errors such as the ones below, I'm posting this thread.

 

Errors this will solve:

1. Cannot deserialize value of type `java.util.HashSet<com.hubspot.inbounddb.associations.base.AssociationSpec>` from Object value

 

2. What are the proper IDs for connecting a note to a contact, and where does the Contact ID actually go? Can I use an email, or does it need to be the contact ID?

 

So, first, let's start with question #2, partially. No, you can't use an email address as the ID, and it needs to be the numerical ID of the contact. Now, let's examine the request.

 

POST /crm/v3/objects/notes

Using the official PHP SDK available on Github:

 

$this->hubspot->apiRequest([

'method' => 'POST',

'path' => '/crm/v3/objects/notes',

'body' => [

'properties' => [

'hs_timestamp' => 1730678665,

'hs_note_body' => "Your note here.",

],

'associations' => [

[

"to" => [

"id" => 123456789, // Don't be decieved by some other posts with 51 or 305 or some short number here. This is the long contact ID from the URL on the contact's profile page.

],

"types" => [

[ // IMPORTANT! Notice that this is a NESTED array! This took me all day to notice that they said typeS, not type, and that while you'll only ever use one type, you need to make this single type nested.

"associationCategory" => "HUBSPOT_DEFINED",

"associationTypeId" => 202, // This is the correct ID used for attaching this brand new note to an existing contact. Do not use 201, which is how you attach a brand new other object to an existing note.

],

],

],

],

],

]);

 

Problem #1 above is solved by nesting the array in "types" as noted in the comments. Problem #2 is also noted in the comments above. (Blame HubSpot for the lack of indentation on the code. I copy and pasted my indented code.)

 

Hopefully this saves someone else countless hours. I'm a seasoned software engineer of nearly 22 years, and this was not easy to come by.

0 Upvotes
1 Reply 1
HMir
Member

Here's how to create a note on a contact through the API.


@NSaad wrote:

I spent hours fighting through this poorly designed API that HubSpot "convieniently" doesn't let you have access to support for its usage. To help you get your note added without errors such as the ones below, I'm posting this thread.

 

Errors this will solve:

1. Cannot deserialize value of type `java.util.HashSet<com.hubspot.inbounddb.associations.base.AssociationSpec>` from Object value

 

2. What are the proper IDs for connecting a note to a contact, and where does the Contact ID actually go? Can I use an email, or does it need to be the contact ID?

 

So, first, let's start with question #2, partially. No, you can't use an email address as the ID, and it needs to be the numerical ID of the contact. Now, let's examine the request.

 

POST /crm/v3/objects/notes

Using the official PHP SDK available on Github:

 

$this->hubspot->apiRequest([

'method' => 'POST',

'path' => '/crm/v3/objects/notes',

'body' => [

'properties' => [

'hs_timestamp' => 1730678665,

'hs_note_body' => "Your note here.",

],

'associations' => [

[

"to" => [

"id" => 123456789, // Don't be decieved by some other posts with 51 or 305 or some short number here. This is the long contact ID from the URL on the contact's profile page.

],

"types" => [

[ // IMPORTANT! Notice that this is a NESTED array! This took me all day to notice that they said typeS, not type, and that while you'll only ever use one type, you need to make this single type nested.

"associationCategory" => "HUBSPOT_DEFINED",

"associationTypeId" => 202, // This is the correct ID used for attaching this brand new note to an existing contact. Do not use 201, which is how you attach a brand new other object to an existing note.

],

],

],

],

],

]);

 

Problem #1 above is solved by nesting the array in "types" as noted in the comments. Problem #2 is also noted in the comments above. (Blame HubSpot for the lack of indentation on the code. I copy and pasted my indented code.)

 

Hopefully this saves someone else countless hours. I'm a seasoned software engineer of nearly 22 years, and this was not easy to come by.


Thank you for sharing this solution

Just to clarify, when using the associationTypeId of 202, is this ID universal for all notes associated with contacts, or could it change depending on other factors, like custom object relationships? And with the hs_timestamp you provided, is that supposed to be in a specific timezone, or does HubSpot handle that automatically as UTC?

0 Upvotes