Thank you for tagging @Jaycee_Lewis.
Hey @rajeev-fas,
This code should point you in the right direction:
import os
from pprint import pprint
from hubspot import HubSpot
from hubspot.crm.companies import ApiException as company_execption
from hubspot.crm.objects.notes import ApiException as engagement_exception
from dotenv import load_dotenv
load_dotenv()
hubspot = HubSpot(access_token=os.getenv("access_token"))
company_id = 5800956379 # ID of the company you want the attachments for
attachment_ids = []
# Attachments are tied to note engagments. Get all notes for the company
try:
get_notes = hubspot.crm.companies.associations_api.get_all(
company_id=company_id, to_object_type="note", limit=500
)
# pprint(get_notes.results) uncomment for debug
except company_execption as e:
print("Exception when calling associations_api->get_all: %s\n" % e)
# Iterate through all the note ids from the response and get their properties
for note in get_notes.results:
try:
get_note = hubspot.crm.objects.notes.basic_api.get_by_id(
note_id=note.to_object_id, properties=["hs_attachment_ids"], archived=False
)
# pprint(get_note.properties) uncomment for debug
attachment_id = get_note.properties["hs_attachment_ids"]
# Check if the note has an attachment
if attachment_id is not None:
id_list = attachment_id.split(";")
# pprint(id_list) uncomment for debug
# Extend the list of attachments
attachment_ids.extend(id_list)
except engagement_exception as e:
print("Exception when calling basic_api->get_by_id: %s\n" % e)
# Print out the complete list of attachment ids. To download use /files/v3/files/{fileId} endpoint
pprint(attachment_ids)
If you found this post helpful, consider helping others in the community to find answers faster by marking this as a solution. I’d really appreciate it.
Cheers,
Chriso