APIs & Integrations

Akamran
Member

Trigger webhook on adding note to a company.

SOLVE

Hi All, I had a query regarding webhooks. I've some companies stored in hubspot. Is it possible to call a webhook when I will add notes to a company?

 

Thanks. 

0 Upvotes
2 Accepted solutions
coldrickjack
Solution
Guide

Trigger webhook on adding note to a company.

SOLVE

Hi @Akamran,

 

Currently it is not possible to create webhooks for events happening directly on Engagement objects (Emails, Notes, Tasks, Meetings and Calls).

 

However an alternative solution to consider is to create a webhook that is triggered anytime the "Last Activity Date" property is updated on the Company. This records the last time a call, chat conversation, LinkedIn message, postal mail, meeting, note, sales email, SMS, or WhatsApp message was logged for a company.

 

See an example of my webhook in my app:

 

Screenshot 2023-08-11 at 15.24.59.png

Anytime I log a note (or any type of engagement for that matter) the webhook is fired and my endpoint receives the payload below:

 

[
    {
        "eventId": 2045645441,
        "subscriptionId": 2219950,
        "portalId": 141307928,
        "appId": 1914445,
        "occurredAt": 1691763855124,
        "subscriptionType": "company.propertyChange",
        "attemptNumber": 0,
        "objectId": 8240965055,
        "propertyName": "notes_last_updated",
        "propertyValue": "1691763854789",
        "changeSource": "ENGAGEMENTS",
        "sourceId": "ObjectPropertyUpdater"
    }
]

 

What you then need to do in order to get the specific engagement information is use the objectId (this is the Company Id) in the payload to retrieve associated engagements. So using the CRM Companies API with the associations parameter we can make a request like this:

 

GET https://api.hubapi.com/crm/v3/objects/companies/8240965055?associations=note
RESPONSE
{
    "id": "8240965055",
    "properties": {
        "createdate": "2023-08-11T14:23:55.046Z",
        "domain": "marvel.com",
        "hs_lastmodifieddate": "2023-08-11T14:24:34.991Z",
        "hs_object_id": "8240965055",
        "name": "Marvel"
    },
    "createdAt": "2023-08-11T14:23:55.046Z",
    "updatedAt": "2023-08-11T14:24:34.991Z",
    "archived": false,
    "associations": {
        "notes": {
            "results": [
                {
                    "id": "19456202967",
                    "type": "company_to_note"
                },
                {
                    "id": "19456203473",
                    "type": "company_to_note"
                }
            ]
        }
    }
}

 

Notice the associations object returned in the response. This contains the ID of all engagements (Notes) on the Company. To get specific information we can use the CRM Engagements endpoint like so:

 

GET https://api.hubapi.com/crm/v3/objects/notes/19456202967?properties=hs_note_body
RESPONSE
    "id": "19456202967",
    "properties": {
        "hs_createdate": "2023-08-11T14:24:14.789Z",
        "hs_lastmodifieddate": "2023-08-11T14:24:14.789Z",
        "hs_note_body": "<div style=\"\" dir=\"auto\" data-top-level=\"true\"><p style=\"margin:0;\">This is a note</p></div>",
        "hs_object_id": "19456202967"
    },
    "createdAt": "2023-08-11T14:24:14.789Z",
    "updatedAt": "2023-08-11T14:24:14.789Z",
    "archived": false
}

 

It's not perfect but it's the only way to achieve what you are trying to do. At least until a point in time where HubSpot supports creating webhooks directly for Engagements.

 

I hope it helps and good luck in your project. 

View solution in original post

0 Upvotes
Jaycee_Lewis
Solution
Community Manager
Community Manager

Trigger webhook on adding note to a company.

SOLVE

Hey, @mharis7 @JPrajapati3  👋 I tested this in my portal and was able to create the webhook. You may need to manually paste the value into the webhook editor.

CleanShot 2024-05-02 at 15.07.12.png

 

Additionally, you can search for this property using the Properties API. Example:

Request

curl --request GET \
  --url 'https://api.hubapi.com/crm/v3/properties/company/notes_last_updated?archived=false' \
  --header 'authorization: Bearer YOUR_ACCESS_TOKEN'

Response

HTTP 200

{
  "updatedAt": "2023-06-26T20:53:54.382Z",
  "createdAt": "2020-06-30T15:57:37.548Z",
  "name": "notes_last_updated",
  "label": "Last Activity Date",
  "type": "datetime",
  "fieldType": "date",
  "description": "The last time a call, chat conversation, LinkedIn message, postal mail, meeting, note, sales email, SMS, or WhatsApp message was logged for a company. This is set automatically by HubSpot based on user actions in the company record.",
  "groupName": "company_activity",
  "options": [],
  "displayOrder": 6,
  "calculated": false,
  "externalOptions": false,
  "hasUniqueValue": false,
  "hidden": false,
  "hubspotDefined": true,
  "modificationMetadata": {
    "archivable": true,
    "readOnlyDefinition": true,
    "readOnlyValue": true
  },
  "formField": false,
  "dataSensitivity": "non_sensitive"
}

 

Have fun building! — Jaycee

 


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !

View solution in original post

20 Replies 20
brusky07
Member

Trigger webhook on adding note to a company.

SOLVE

Many thanks for this.
But it seems that the "Last Activity Date" property is NOT updated on the Company where we MODIFY a Note attached to the Company (ONLY updated when first created).
Or is there another way ?
Many thanks

0 Upvotes
coldrickjack
Guide

Trigger webhook on adding note to a company.

SOLVE

Hey @bru, unfortunatley not I'm afraid.

 

The original use was to support triggering a webhook when a note was created, whilst we can't directly subscribe to those events on the engagement object itself we can use the "Last Activity Date" as mentioned. It's a company property that represents the time a note was last logged (added) to the record.

 

There isn't a company property that stores the last time an update was made to a given note. I've also tested to see if at the very least "hs_lastmodifieddate" would update but from my testing it does not.

 

The only option at present (that I can see) is to poll for changes periodically using the Engagments API. The ideal of course would be to configure a webhook to detect updates on the engagement itself but it's not supported by HubSpot at the moment and I'm not sure if and when HubSpot plans to support it either. 

 

0 Upvotes
mharis7
Member

Trigger webhook on adding note to a company.

SOLVE

i am unable to find last activity date property

0 Upvotes
brusky07
Member

Trigger webhook on adding note to a company.

SOLVE
Many thanks ! In fact I had reached the same conclusion, but then I'm happy to have your confirmation !
Many thanks for your help !
coldrickjack
Solution
Guide

Trigger webhook on adding note to a company.

SOLVE

Hi @Akamran,

 

Currently it is not possible to create webhooks for events happening directly on Engagement objects (Emails, Notes, Tasks, Meetings and Calls).

 

However an alternative solution to consider is to create a webhook that is triggered anytime the "Last Activity Date" property is updated on the Company. This records the last time a call, chat conversation, LinkedIn message, postal mail, meeting, note, sales email, SMS, or WhatsApp message was logged for a company.

 

See an example of my webhook in my app:

 

Screenshot 2023-08-11 at 15.24.59.png

Anytime I log a note (or any type of engagement for that matter) the webhook is fired and my endpoint receives the payload below:

 

[
    {
        "eventId": 2045645441,
        "subscriptionId": 2219950,
        "portalId": 141307928,
        "appId": 1914445,
        "occurredAt": 1691763855124,
        "subscriptionType": "company.propertyChange",
        "attemptNumber": 0,
        "objectId": 8240965055,
        "propertyName": "notes_last_updated",
        "propertyValue": "1691763854789",
        "changeSource": "ENGAGEMENTS",
        "sourceId": "ObjectPropertyUpdater"
    }
]

 

What you then need to do in order to get the specific engagement information is use the objectId (this is the Company Id) in the payload to retrieve associated engagements. So using the CRM Companies API with the associations parameter we can make a request like this:

 

GET https://api.hubapi.com/crm/v3/objects/companies/8240965055?associations=note
RESPONSE
{
    "id": "8240965055",
    "properties": {
        "createdate": "2023-08-11T14:23:55.046Z",
        "domain": "marvel.com",
        "hs_lastmodifieddate": "2023-08-11T14:24:34.991Z",
        "hs_object_id": "8240965055",
        "name": "Marvel"
    },
    "createdAt": "2023-08-11T14:23:55.046Z",
    "updatedAt": "2023-08-11T14:24:34.991Z",
    "archived": false,
    "associations": {
        "notes": {
            "results": [
                {
                    "id": "19456202967",
                    "type": "company_to_note"
                },
                {
                    "id": "19456203473",
                    "type": "company_to_note"
                }
            ]
        }
    }
}

 

Notice the associations object returned in the response. This contains the ID of all engagements (Notes) on the Company. To get specific information we can use the CRM Engagements endpoint like so:

 

GET https://api.hubapi.com/crm/v3/objects/notes/19456202967?properties=hs_note_body
RESPONSE
    "id": "19456202967",
    "properties": {
        "hs_createdate": "2023-08-11T14:24:14.789Z",
        "hs_lastmodifieddate": "2023-08-11T14:24:14.789Z",
        "hs_note_body": "<div style=\"\" dir=\"auto\" data-top-level=\"true\"><p style=\"margin:0;\">This is a note</p></div>",
        "hs_object_id": "19456202967"
    },
    "createdAt": "2023-08-11T14:24:14.789Z",
    "updatedAt": "2023-08-11T14:24:14.789Z",
    "archived": false
}

 

It's not perfect but it's the only way to achieve what you are trying to do. At least until a point in time where HubSpot supports creating webhooks directly for Engagements.

 

I hope it helps and good luck in your project. 

0 Upvotes
mharis7
Member

Trigger webhook on adding note to a company.

SOLVE

i dont have notes_last_updated option in company i have this inside contact @coldrickjack 

0 Upvotes
JPrajapati3
Participant

Trigger webhook on adding note to a company.

SOLVE

Hello @coldrickjack,

I'm not able to find the event which you subscribe for notes. 
Can you please guide me from where I can get the notes_last_updated event in webHook?

 

notes_last_updated  it is available while creating a WorkFlow.
Let me correct If I'm wrong. 

Thanks in advance.

0 Upvotes
mharis7
Member

Trigger webhook on adding note to a company.

SOLVE

same man

let me know if you find something

0 Upvotes
Jaycee_Lewis
Solution
Community Manager
Community Manager

Trigger webhook on adding note to a company.

SOLVE

Hey, @mharis7 @JPrajapati3  👋 I tested this in my portal and was able to create the webhook. You may need to manually paste the value into the webhook editor.

CleanShot 2024-05-02 at 15.07.12.png

 

Additionally, you can search for this property using the Properties API. Example:

Request

curl --request GET \
  --url 'https://api.hubapi.com/crm/v3/properties/company/notes_last_updated?archived=false' \
  --header 'authorization: Bearer YOUR_ACCESS_TOKEN'

Response

HTTP 200

{
  "updatedAt": "2023-06-26T20:53:54.382Z",
  "createdAt": "2020-06-30T15:57:37.548Z",
  "name": "notes_last_updated",
  "label": "Last Activity Date",
  "type": "datetime",
  "fieldType": "date",
  "description": "The last time a call, chat conversation, LinkedIn message, postal mail, meeting, note, sales email, SMS, or WhatsApp message was logged for a company. This is set automatically by HubSpot based on user actions in the company record.",
  "groupName": "company_activity",
  "options": [],
  "displayOrder": 6,
  "calculated": false,
  "externalOptions": false,
  "hasUniqueValue": false,
  "hidden": false,
  "hubspotDefined": true,
  "modificationMetadata": {
    "archivable": true,
    "readOnlyDefinition": true,
    "readOnlyValue": true
  },
  "formField": false,
  "dataSensitivity": "non_sensitive"
}

 

Have fun building! — Jaycee

 


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !
JPrajapati3
Participant

Trigger webhook on adding note to a company.

SOLVE

Thank you for your reply.

Yes, When we just paste the notes_last_updated value in the property change event then we can subscribe the event.

Thank you so much @Jaycee_Lewis 


0 Upvotes
VBossio
Participant

Trigger webhook on adding note to a company.

SOLVE

What is the propertyValue in the initial webhook payload above? 

"propertyValue": "1691763854789",

It appears to be a numer ic identifier. What does that number represent and can a lookup be performed to get a string value of what it represents?

0 Upvotes
coldrickjack
Guide

Trigger webhook on adding note to a company.

SOLVE

Hey @VBossio,

 

It's a UNIX timestamp (1691763854789) and represents the date (Fri Aug 11 2023) the note was last updated. You'd need to convert that in your code to get a readable date.

0 Upvotes
VBossio
Participant

Trigger webhook on adding note to a company.

SOLVE
Thank you, was able to figure that out actually.
That's kind of odd though, wouldn't the NoteId (or EngagementId) what was changed be more useful?
Then you could get the last updated date/time from the Note/Engagement.
Not having a webhook for Note changes is a huge issue.
How do you suggest handling bi-directional Notes updates between Hubspot and another system?

0 Upvotes
coldrickjack
Guide

Trigger webhook on adding note to a company.

SOLVE

Hey @VBossio,

 

Absolutely, I agree that lack of webhook support for Engagements is an issue. I don't work at HubSpot so unfortunatley have no visibility as to if and when they plan to support this. 

 

Until they do the only real workarounds are similar to the one in this thread, whereby we use the "Last Activity Date" to detect when an Engagement was updated on a company or any CRM record and then retrieve the associated Engagements for that object.

 

0 Upvotes
VBossio
Participant

Trigger webhook on adding note to a company.

SOLVE
Thank you, I understand it's difficult to project what Hubspot will do since you are no longer working there.
The workaround would be fine, except I tested as follows and it doesn't look like "updates" to Engagements (changing a Note for example) change anything in the Company object:

1. Called the get company by Id API endpoint with all properties and saved the response JSON.
2. Changed a Note that is associated with the company.
3. Called the get company by Id API endpoint again with all properties and saved the response JSON
4. The JSON saved in Steps 1 and 3 was identical.
It appears that only adding new Engagements updates the company Last Activity Date.
brusky07
Member

Trigger webhook on adding note to a company.

SOLVE

Thanks @coldrickjack,

 

But in fact the "Last Activity Date" property is NOT updated on the Company when we MODIFY a Note attached to the Company (ONLY updated when first created).

I think...

 

0 Upvotes
coldrickjack
Guide

Trigger webhook on adding note to a company.

SOLVE

Hey @brusky07,

 

Yes, apologies, there is quite a lot of back and forth in the thread but I recall that we spoke about this so I would defer back to my original answer on that here. In short:

 

  • If you are simply hoping to trigger a webhook when a note is added the approach of using "Last Activity Date" will work. 
  • If you are hoping to trigger a webhook when a note is updated the approach of using "Last Activity Date" will not work. Instead you need to poll the Engagements API.
0 Upvotes
brusky07
Member

Trigger webhook on adding note to a company.

SOLVE

@coldrickjack , understood, many thanks for your confirmation.

0 Upvotes
coldrickjack
Guide

Trigger webhook on adding note to a company.

SOLVE

No worries @brusky07 and @VBossio. I hope that it was in some way helpful and wish you best of luck with the project moving forward. Hopefully we will see support for Engagment Webhooks in the not to distant future!!! 🤞

VBossio
Participant

Trigger webhook on adding note to a company.

SOLVE

I have found this endpoint which can be used to return all engagements with a last modified date "since" a value that you can provide as a parameter. 

https://legacydocs.hubspot.com/docs/methods/engagements/get-recent-engagements

 

The "since" value has to be provided in UNIX timestamp format but it appears to work.  My only concern is that this specific endpoint is only available with API v1 and that it may be deprecated at some point.

0 Upvotes