APIs & Integrations

Brik
Member

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.

Capture d’écran 2022-09-19 à 16.57.45.png

 

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

Capture d’écran 2022-09-19 à 17.06.50.png

 

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

Capture d’écran 2022-09-19 à 17.15.03.png 

 

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 !

0 Upvotes
2 Replies 2
JMadrone
Member

Associate files to custom object attachment

For anyone that finds this post in the future, this app solves for this kind of thing natively in the UI using workflow actions: https://ecosystem.hubspot.com/marketplace/apps/marketing/data-management/file-attachment-association...

While not the actual code necessary to do this, the app solves teh use case of attaching files to objects.

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

Associate files to custom object attachment

Hey, @Brik 👋 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!

    note1.png

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


HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates.
Learn More.


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !