APIs & Integrations

andgom
Participant

Create associations between companies and files

SOLVE

Hi, 

I am a noobie developer and I am currently trying to associate a file with a company.  So, as far as I know, it seems that associations can be done with tickets, deals, other companies, etc... You can actually get the associations between to specific object making a POST request to https://api.hubapi.com/crm/v3/associations/{fromObjectType}/{toObjectType}/batch/read?hapikey=HAPIKE...  and specifying the id of the "fromObjectType" object at the body.

 

This works with tickets, other companies, etc... but when I try to do it with Attachments

it returns a 400 with this body:

 

{
    "status": "error",
    "message": "Unable to infer object type from: attachment",
    "correlationId": "d772d739-45bd-49cc-a45c-c95ba4ff2d84"
}

 

I've seen that, from the CRM web, you can actually do it, you can associate a company with files or "Attachments"  at the right sidebar as you can see in the screenshot. associations.PNG

 

With this said, why is it possible to associate a company with a file from the CRM web and not via the API? If  I am wrong and it is possible to do this via the API, how is the object type for Attachments called in HubSpot? Also if you have a better idea or you know a better way to handle my situation how would you do it?

0 Upvotes
1 Accepted solution
Aleeson
Solution
HubSpot Employee
HubSpot Employee

Create associations between companies and files

SOLVE

Hey there andgom, cheers for engaging with the Community. I'm not a developer myself, but I can provide some insight on this one:

 

Attachments (on the Company or Contact Record) reflect files that were attached to some Engagement on the Contact record- Notes, emails, etc. As such, they don't interact directly with the Files API that you seem to be using here. They're also not Objects- From HubSpot's point of view, Objects are Deals, Companies, Contacts, Tickets, Line Items/Products. 

 

Adding an Attachment to an Object record (like a Contact or Company) would in this case involve using the Engagements API (I'm aware that this is the Legacy version- at time of writing, the updated Engagements API has yet to be released, so the Legacy version is the most recent stable release). You'll note at the documentation page I've linked that there's an optional  attachments parameter you can use when creating Engagements, that allow you to associate previously-uploaded files with a Company/Contact/Deal etc, which will show up under the Attachments tab (the individual file IDs can be found using the Files API).

 

Hope this helps a bit!
Al

View solution in original post

2 Replies 2
Aleeson
Solution
HubSpot Employee
HubSpot Employee

Create associations between companies and files

SOLVE

Hey there andgom, cheers for engaging with the Community. I'm not a developer myself, but I can provide some insight on this one:

 

Attachments (on the Company or Contact Record) reflect files that were attached to some Engagement on the Contact record- Notes, emails, etc. As such, they don't interact directly with the Files API that you seem to be using here. They're also not Objects- From HubSpot's point of view, Objects are Deals, Companies, Contacts, Tickets, Line Items/Products. 

 

Adding an Attachment to an Object record (like a Contact or Company) would in this case involve using the Engagements API (I'm aware that this is the Legacy version- at time of writing, the updated Engagements API has yet to be released, so the Legacy version is the most recent stable release). You'll note at the documentation page I've linked that there's an optional  attachments parameter you can use when creating Engagements, that allow you to associate previously-uploaded files with a Company/Contact/Deal etc, which will show up under the Attachments tab (the individual file IDs can be found using the Files API).

 

Hope this helps a bit!
Al

andgom
Participant

Create associations between companies and files

SOLVE

Thank you very much @Aleeson! This is exactly what I was looking for! 

0 Upvotes