APIs & Integrations

JZhao
Participant

How can I delete attachment from contact via API?

I am looking for deleting attachment from Hubspot contact via API but I can't find it. Can anyone show me how to do that?

3 Replies 3
Franci
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

How can I delete attachment from contact via API?

Hi Everyone,

 

I work for a HubSpot Diamond Partner. We have developed an app for the marketplace that aims to solve the issue of bulk deleting attachments. Our app allows users to access a CRM card showing all the attachments associated with an object record and easily delete them in bulk.

 

We are seeking beta testers who can try our app at no cost, provide valuable feedback, and assist us in enhancing the overall usability of the product.

 

👉 Join the Beta Test -> Installation link 🔗

👉 How it works document -> PDF

 

While you're here, don't forget to check out our other apps in the HubSpot Marketplace for more helpful solutions!

 

Cheers!

Francesco Collacciani

HubSpot Specialist @ Exelab

#1 HubSpot Diamond Partner in Italy

emailAddress
francesco.collacciani@exelab.com
website
https://www.exelab.com/en/
Get in touch with us!
0 Upvotes
JBeatty
Guide | Diamond Partner
Guide | Diamond Partner

How can I delete attachment from contact via API?

Hi @JZhao,

 

Attachments are stored within engagements. So in order to delete an attachment, you must delete the engagement that it goes along with, which could be a note, task, email, or logged call. If you do not know the engagement ID we will need to do a few steps.

 

First, by using the Get associations for a CRM object endpoint, we can grab all the engagement IDs associated with a Contact:

 

 

 

//Example https call: Note that "9" is the id for contact to engagement 
https://api.hubapi.com/crm-associations/v1/associations/{Contact_ID}/HUBSPOT_DEFINED/9?hapikey=demo

//Example Response:
{
  "results": [
    13615120897,
    13615494311,
    14199337320
  ],
  "hasMore": false,
  "offset": 14199337320
}

 

 

 

Then once you have the engagement IDs you can iterate through them calling the Get an engagement endpoint. In the response, you will see details about the engagement including a key called "attachments" which will have a value of an array of associated file IDs. From this response, you should be able to determine which of those returned IDs is the one you wish to delete.

 

Then you can call the DELETE an Engagement endpoint to delete the engagement. Another option is to call the Update an Engagement endpoint with a payload of:

 

 

 

{
 "attachments": [ ]
}

 

 

To update the engagement to have no attached files.

 

Another note is that within the attachment key from the get engagement endpoint is the file ID of the attachment, so you could also call the Delete a file by ID endpoint.

 

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Joshua Beatty
Software Developer with Pearagon

Still have questions? Let's Talk

JZhao
Participant

How can I delete attachment from contact via API?

Thanks for your response.

 

I also found this file API: https://developers.hubspot.com/docs/api/files/files

 

What is the different between file api and engagement API? when should I use each of them?

0 Upvotes