Attaching Files to a Custom Object

Attaching files to custom objects seamlessly integrates documentation within your data flow, ensuring relevant information is just a click away. In this comprehensive guide, we’ll unveil the step-by-step process to efficiently attach files to a custom object in HubSpot.

Step 1: Get the Associated Id

API Documentation: CRM Associations

API Method: GET

https://api.hubapi.com/crm/v4/associations/{fromObjectType}/{toObjectType}/labels

For our purpose, we want to associate NOTES to a CUSTOM OBJECT ID:

https://api.hubapi.com/crm/v4/associations/notes/{custom_object_id}/labels

Expected Response

{"results": [{"category": "USER_DEFINED","typeId": 999, "label": null}]}

Save the typeId value from the response. We’ll need it for later steps.

Step 2: Upload the File

API Documentation: Files API

API Method: POST

https://api.hubapi.com/files/v3/files

While making the POST request, ensure you attach a file using the file key. Additionally, specify the folderId (can be any value) and provide any options as a JSON object.

Upon successfully posting the file, you should receive a 201 response containing a JSON object. Extract the id value from this object as we’ll be using it in the next step.

Step 3: Create a Note

Files are integrated into HubSpot via notes. Thus, creating a note is essential for our goal.

API Documentation: CRM Notes

API Method: POST

https://api.hubspot.com/crm/v3/objects/notes

Send the following raw JSON in the body:

{"properties":{"hs_timestamp": "{put_timestamp_here}","hubspot_owner_id":"{put_owner_id_here}","hs_attachment_ids":"{use the id from Step 2}","hs_note_body":"This is a test note and can be anything"}}

On successful execution, you’ll get a 201 response with a JSON object. Keep the id from this object handy for the next step.

Step 4: Associate the Note to the Record

Finally, we need to associate the note we created with the actual record in HubSpot.

API Documentation: CRM Notes

API Method: PUT

https://api.hubspot.com/crm/v3/objects/notes/{{note_id_from_step3}/associations/{custom_object_id}/{the_id_of_the_specific_record}/{typeId_from_step1}

If everything worked correctly, you should receive a 200 OK response, confirming that the file has been successfully attached to the custom object in HubSpot.

By following these steps, you can efficiently integrate and attach files to any custom object in HubSpot using the platform’s v3 APIs. Happy integrating!

Hi, @ABollinger :waving_hand: Thank you very much for taking the time to put this together! — Jaycee

Very happy to help! We spent a few hours getting it working.

Hi,

Would you happen to know if you are using any specific scopes? I’ve done approximately the same thing for a deal, and I can see the note be associated in postman, but when I go to the deal I see that the attachment has been deleted. Any thoughts?

What do you mean when you say deleted? There should be a note and the attachment in the sidebar.