APIs & Integrations

SR36
Member

Getting Associations in Batch APIs

SOLVE

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/\?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"

}

0 Upvotes
1 Accepted solution
dennisedson
Solution
HubSpot Product Team
HubSpot Product Team

Getting Associations in Batch APIs

SOLVE

@SR36 

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

View solution in original post

0 Upvotes
6 Replies 6
CMarl
Participant

Getting Associations in Batch APIs

SOLVE

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

0 Upvotes
dennisedson
Solution
HubSpot Product Team
HubSpot Product Team

Getting Associations in Batch APIs

SOLVE

@SR36 

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

0 Upvotes
SR36
Member

Getting Associations in Batch APIs

SOLVE

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

0 Upvotes
sfroment
Member

Getting Associations in Batch APIs

SOLVE

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-deal...

Thanks ! 

SR36
Member

Getting Associations in Batch APIs

SOLVE

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 😞

 
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 
 
sfroment
Member

Getting Associations in Batch APIs

SOLVE

Yes indeed it is the solution I also implemented 😞 

0 Upvotes