La fonction de suggestion automatique permet d'affiner rapidement votre recherche en suggérant des correspondances possibles au fur et à mesure de la frappe.
Contributeur de premier rang | Partenaire solutions Diamond
finding all the attachments
Résolue
Hey there!
We've just released the Attachment From Form app on the HubSpot Marketplace!
If you're tired of playing hide-and-seek with files in your HubSpot database, you're in the right place! Attachment From Form simplifies the process by linking files submitted in a form directly to the corresponding contact record. Say goodbye to the endless file hunt and say hello to effortless access!
Here are the standout features:
1. Effortless Form-Attachment Connection: Easily link your forms to contact attachments.
2. Efficient File Retrieval: When a contact submits a file type property in your form, it appears in the attachment card, saving you valuable time.
3. Organized Activity Section: Attachment From Form creates custom activities, making it a breeze to find attached files on the contact page while maintaining a comprehensive property attribution history.
Get organized and supercharge your efficiency with the Attachment From Form app now! And the best part? It won't cost you a dime.
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.
in general, if you upload any attachments, a note gets created where the respective file can also be found. That is btw also the case when you create attachments through a form upload.
To get to the file/s from the API, you have to go through the associated activities to find them. There is no to_object_type called attachments or something similar.
This might sound stupid, but maybe you're currently filtering notes in the activities when looking at the record.
Now, it is hard for us to diagnose these things at a distance. So without any more information, it will be very hard for us to help you any further. For example: How are these attachments created in the first place?