Associate files to custom object attachment

Hi,

I am trying to link files uploaded throught the API with my “assets” custom objects.

My upload went well and I can see my files in Hubspot.

First I tried this way, it worked for contactIds and my file is now link to my test contact, I can see the file in my contact attachments on Hubspot.

So I tried to also add the “assetsIds” but it didn’t worked for this association.

Here is the response, we can see in associations that I don’t have my “assets” custom object.

So instead I tried this way but I am getting a 415 ‘Unsupported Media Type’ (I also tried with the v3)

I am a bit confused, I tried to look into differents posts here and I read the documentation about engagement, associations and custom objects but I can’t figure out how to link my files to my custom objects attachment. Hopefully you can help me !

Thanks !

Hey, @Brik :waving_hand: Thanks for reaching out. I’ve done this a few times now and always find it a bit mysterious.

Here’s my quick test:

  • I created a note and grabbed the ID 25906880309

  • I have a test custom object called Boats

  • I grabbed the objectType and objectID
    Type — 2-7913954
    ID — 1976776222

  • I used this endpoint — Associate a note with another object
    PUT /crm/v3/objects/notes/{noteId}/associations/{toObjectType}/{toObjectId}/{associationType}​

  • Request

    curl --request PUT \
     --url https://api.hubapi.com/crm/v3/objects/notes/25906880309/associations/2-7913954/1976776222/boat_to_note \
     --header 'authorization: Bearer YOUR_ACCESS_TOKEN'​
    
  • Response

    HTTP 200
    
    {
     "id": "25906880309",
     "properties": {
     "hs_createdate": "2022-09-21T18:16:57.395Z",
     "hs_lastmodifieddate": "2022-09-21T18:16:57.395Z",
     "hs_object_id": "25906880309"
     },
     "createdAt": "2022-09-21T18:16:57.395Z",
     "updatedAt": "2022-09-21T18:16:57.395Z",
     "archived": false,
     "associations": {
     "p22245342_boat": {
     "results": [
     {
     "id": "1976776222",
     "type": "boat_to_note"
     }
     ]
     }
     }
    }​
    
  • Success!

I hope this helps get you moving in the right direction. Have fun building! — Jaycee

For anyone that finds this post in the future, this app solves for this kind of thing natively in the UI using workflow actions: HubSpot Marketplace
While not the actual code necessary to do this, the app solves teh use case of attaching files to objects.