Getting Associations in Batch APIs

Is there a way to retrieve associations in a Batch Read. For example, when retrieving a single contact, I can request for associations via the GET API as follows

curl --request GET --url [https://api.hubapi.com/crm/v3/objects/contacts/251/\\](https://api.hubapi.com/crm/v3/objects/contacts/251/\)?associations\=notes --header ‘authorization: Bearer <token>’ | json_pp

% Total % Received % Xferd Average Speed Time Time Time Current

                             Dload  Upload   Total   Spent    Left  Speed

100 432 0 432 0 0 352 0 --:--:-- 0:00:01 --:--:-- 357

{

“archived” : false,

“associations” : {

  "notes" : {

     "results" : \[

        {

           "id" : "19668463257",

           "type" : "contact\_to\_note"

        },

        {

           "id" : "19793682071",

           "type" : "contact\_to\_note"

        }

     ]

  }

},

“createdAt” : “2022-03-03T09:23:21.321Z”,

“id” : “251”,

“properties” : {

  "createdate" : "2022-03-03T09:23:21.321Z",

  "email" : "bcooper@biglytics.net",

  "firstname" : "Bryan",

  "hs\_object\_id" : "251",

  "lastmodifieddate" : "2022-03-04T03:08:28.978Z",

  "lastname" : "Cooper"

},

“updatedAt” : “2022-03-04T03:08:28.978Z”

}

But when trying to use batch operations is there a way to retrieve associations in the response. I tried the following but did not work. From API there seems to be no way to achieve this. Is there any other way to do this?

curl --request POST \

--url https://api.hubapi.com/crm/v3/objects/contacts/batch/read \

--header ‘authorization: Bearer <token>’ \

--header ‘content-type: application/json’ \

--data '{

“inputs”: [

{

  "id": "251"

}

],

“associations”: [

"notes"

]

}’ | json_pp

% Total % Received % Xferd Average Speed Time Time Time Current

                             Dload  Upload   Total   Spent    Left  Speed

100 501 0 415 100 86 335 69 0:00:01 0:00:01 --:--:-- 408

{

“completedAt” : “2022-03-08T06:27:11.024Z”,

“results” : [

  {

     "archived" : false,

     "createdAt" : "2022-03-03T09:23:21.321Z",

     "id" : "251",

     "properties" : {

        "createdate" : "2022-03-03T09:23:21.321Z",

        "email" : "bcooper@biglytics.net",

        "firstname" : "Bryan",

        "hs\_object\_id" : "251",

        "lastmodifieddate" : "2022-03-04T03:08:28.978Z",

        "lastname" : "Cooper"

     },

     "updatedAt" : "2022-03-04T03:08:28.978Z"

  }

],

“startedAt” : “2022-03-08T06:27:10.999Z”,

“status” : “COMPLETE”

}

@SR36

Have you explored the CRM search api? You can return associations with that

Thanks. I ended up using the search API, but this was sub optimal as I already had the list of contacts with ids

Hey,

@SR36 @dennisedson
How did you return the associations using the search api ?
It seems like many aren’t knowing how to do this also https://community.hubspot.com/t5/APIs-Integrations/Get-associations-with-deals-from-crm-objects-deals-search/m-p/321104
Thanks !

Hi @sfroment ,

I dont think we can get associations via the search API. As a result I had to do this in a sub optimal convoluted way :disappointed_face:

1) Execute a search query

2) For all returned records, call the batch association API to get the list of associations

3) The returned association is in turn sparse, it does not have the name of the contact, company or deal. So make further batch requests to get these information

This is definitely not ideal. I’m not sure why assocaitions is not exposed in search while its exposed in list API

Yes indeed it is the solution I also implemented :disappointed_face:

How did you get batch associations from the API? I can’t seem to find that functionality. Can only fetch associations one at a time.

@dennisedson it appears we cannot get associations through the search api either. please advise..