Hi, @SSharma043👋 Were you able to get this one sorted out? If not, I'll share a quick example using Postman.
Summary:
Upload the file
Create the Note
Associate the File to the Note
Associate the Note to the Object
Steps
Upload your file via API and note the value for “id”
Files added can be associated to an Object as a Note
Use the 'id” vale as the value for “hs_attachment_ids” when creating a note
POST https://api.hubapi.com/crm/v3/objects/notes
Then you can make a call to associate the Note to a Deal
PUT https://api.hubspot.com/crm/v3/objects/notes/{note_ID}/associations/deal/{deal_ID}/214
I hope this helps you or the next person who is looking to upload and associate files to objects in this manner.
Best,
Jaycee
Join us on March 27th at 12 PM for the Digital Essentials Lab, an interactive session designed to redefine your digital strategy!
Engage with expert Jourdan Guyton to gain actionable insights, participate in live Q&A, and learn strategies to boost your business success. Don't miss this opportunity to connect and grow—reserve your spot today!
Did you know that the Community is available in other languages? Join regional conversations by changing your language settings !
Hello guys, we are new users on hubspot and recently started using Hubspot. We are currently evaluating the hubspot and trying to view/download the file attachments that comes through our website to Hubspot. We see the right file name on the object but trying to view/download the file name it gives us error of "This doesn't appear to reference a file in your hubspot account. It may have been edited or removed".
We tried creating a custom field called attachments and make its type as file but no results. Can anyone walkthrough us with step by step guide? Very obliged to get the support from community.
fev 1, 202412:13 AM - editado fev 1, 202412:15 AM
Participante
Attach file to deal record using API
resolver
here's a post of the actual code in python, assuming you've got a url to the attachment you want to associate.
literally just fill in your auth_key and HubSpot ID and this will work.
your private app (with the auth_key) will need to have deal permissions and file permissions
# this script uploads a file to hubspot, and then associates it to a deal using a note
# from this hubspot community post: https://community.hubspot.com/t5/APIs-Integrations/Attach-file-to-deal-record-using-API/m-p/719945#M58797
# from this hubspot files documentation: https://developers.hubspot.com/docs/api/files/files
# from this hubspot notes documentation: https://developers.hubspot.com/docs/api/crm/notes
# from this hubspot associations documentation: https://developers.hubspot.com/docs/api/crm/associations
import requests, json, time
auth_key = "YOUR_AUTH_KEY"
HUB_ID = YOUR_HUB_ID # just for the print statements at the end
def upload_file(file_name, file_url):
file_id = ""
# upload the file
url = f"https://api.hubapi.com/files/v3/files/import-from-url/async"
headers = {'content-type': 'application/json','authorization': f"Bearer {auth_key}"}
data = {
"folderPath": "/",
# "folderId": ""
"access": "PUBLIC_INDEXABLE",
"name": file_name,
"url": file_url
}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.status_code)
# print(response.text)
task_id = json.loads(response.text)['id']
# ping until the upload is completed, then return the file ID
while True:
time.sleep(2)
url = f"https://api.hubapi.com/files/v3/files/import-from-url/async/tasks/{task_id}/status"
response = requests.get(url, headers=headers)
print(response.status_code)
response_json = json.loads(response.text)
if response_json['status'] == "COMPLETE":
file_id = response_json['result']['id']
break
return file_id
def associate_file_deal(fileId, dealId):
# associate the file to a note & associate the note to a deal
url = f"https://api.hubapi.com/crm/v3/objects/notes"
headers = {'content-type': "application/json",'authorization': f"Bearer {auth_key}"}
data = {
"associations": [{
"types": [{
"associationCategory": "HUBSPOT_DEFINED",
"associationTypeId": 214
}],
"to": {
"id": dealId
}
}],
"properties": {
"hs_note_body": "",
"hs_timestamp": int(time.time())*1000, # current time in ms
"hs_attachment_ids": fileId
}
}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.status_code)
# print(response.text)
if __name__ == "__main__":
file_name = "catanrules.pdf"
file_url = "https://www.catan.com/sites/default/files/2021-06/catan_base_rules_2020_200707.pdf"
deal_id = 15236862608
file_id = upload_file(file_name, file_url)
associate_file_deal(file_id, deal_id)
print(f"https://app.hubspot.com/files/{HUB_ID}/?sortDirection=descending&orderBy=updated&showDetails={file_id}")
print(f"https://app.hubspot.com/contacts/{HUB_ID}/record/0-3/{deal_id}")
Join us on March 27th at 12 PM for the Digital Essentials Lab, an interactive session designed to redefine your digital strategy!
Engage with expert Jourdan Guyton to gain actionable insights, participate in live Q&A, and learn strategies to boost your business success. Don't miss this opportunity to connect and grow—reserve your spot today!
Did you know that the Community is available in other languages? Join regional conversations by changing your language settings !
Hi, @SSharma043👋 Were you able to get this one sorted out? If not, I'll share a quick example using Postman.
Summary:
Upload the file
Create the Note
Associate the File to the Note
Associate the Note to the Object
Steps
Upload your file via API and note the value for “id”
Files added can be associated to an Object as a Note
Use the 'id” vale as the value for “hs_attachment_ids” when creating a note
POST https://api.hubapi.com/crm/v3/objects/notes
Then you can make a call to associate the Note to a Deal
PUT https://api.hubspot.com/crm/v3/objects/notes/{note_ID}/associations/deal/{deal_ID}/214
I hope this helps you or the next person who is looking to upload and associate files to objects in this manner.
Best,
Jaycee
Join us on March 27th at 12 PM for the Digital Essentials Lab, an interactive session designed to redefine your digital strategy!
Engage with expert Jourdan Guyton to gain actionable insights, participate in live Q&A, and learn strategies to boost your business success. Don't miss this opportunity to connect and grow—reserve your spot today!
Did you know that the Community is available in other languages? Join regional conversations by changing your language settings !
Hi @Jaycee_Lewis , can you share an example for how this would work on Python? novice coder here and I'm having trouble getting the file upload to work on Python