We can see uploaded documents for the company shown under the activity notes tab. However, we couldn’t find any API to get the attached file URL to download the pdf document from an external application. Highly appreciate it if anyone can guide us to locate the relevant API endpoint and properties.
Hey @AVidanagamage,
Attachments are linked to records in the CRM via the Note object. Hence why we see it appearing under the notes tab in your screenshot. In order to retrieve the actual file there are a number of things we need to do. There isn’t a single endpoint we can hit to retrieve this data.
Step 1: Get the Note ID
The first thing is to obtain the ID of the note in question. One way to do this is to make a call to the Contacts API which returns all of the associated note IDs.
GET https://api.hubapi.com/crm/v3/objects/contacts/{contactId}?associations=notes
RETURNS:
"associations": {
"notes": {
"results": [
{
"id": "19150934978",
"type": "contact_to_note"
}
]
}
}
Step 2: Get the attachment ID
The note itself is an object (an Engagement object to be precise) and has properties associated to it. One of those properties is called “hs_attachment_ids” which is described as “The IDs of the files that are attached to the engagement”. To do this we make a call using the Notes API:
GET https://api.hubapi.com/crm/v3/objects/notes/{noteId}?properties=hs_attachment_ids
RESPONSE:
"properties": {
"hs_attachment_ids": "75327070660",
"hs_createdate": "2023-07-27T07:07:30.054Z",
"hs_lastmodifieddate": "2023-07-27T07:07:30.054Z",
"hs_object_id": "19150934978"
}
Step 3: Get the attachment metadata
Within the response above we are provided a value for “hs_attachment_ids” this is basically the ID of the file associated to the note and attached to the Contact. The final step is to retrieve the file. This can be done using the Files API. Specifically the below request:
GET https://api.hubapi.com/files/v3/files/{fileId}
{
"id": "75327070660",
"createdAt": "2023-07-27T07:07:29.645Z",
"updatedAt": "2023-07-27T07:07:29.645Z",
"archived": false,
"name": "contract",
"path": "contract.pdf",
"size": 13264,
"type": "DOCUMENT",
"extension": "pdf",
"defaultHostingUrl": "https://140281183.fs1.hubspotusercontent-eu1.net/hubfs/140281183/contract.pdf",
"url": "https://140281183.fs1.hubspotusercontent-eu1.net/hubfs/140281183/contract.pdf",
"isUsableInContent": true,
"access": "HIDDEN_PRIVATE"
}
Notice above the “url” attribute. That contains a link to the specific file within Hubspot. I should add I omitted some other pieces of information returned in the responses above because they weren’t relevant and would make this post a lot longer than it is but the above are the important parts required to achieve what you need!
I hope that helps!
