API GET Associations Contact <> Companies - can't manage to get all associations ?

Hello,

I can’t manage to get all associations between objects.

For example here are the contacts that are assigned to this company

When I GET the data in the /associations endpoint, I retrieve only 2 contacts for this company..

Did it happen to any of you ? What could be the reason (these contacts were never archived..)

Thanks

Hi, @mandou13 :waving_hand: Thanks for the question and for including those details. To help the community assist you can you add the following, please?

  • The specific associations end point you are making your request to
  • The request you are sending (minus any private information)
  • Can you get the expected results if you test from the documentation page? Or using a tool like Postman?

I ran a quick test and received the expected associations. Here’s my test:

  • I have an app test portal
  • I created a private app with the needed scopes
  • Make a test company and added six associated contacts (to match your example)

  • Endpoint used
    GET /crm/v4/objects/{objectType}/{objectId}/associations/{toObjectType}​

  • Request

    curl --request GET \
     --url 'https://api.hubapi.com/crm/v4/objects/0-2/9291675216/associations/0-1?limit=500' \
     --header 'authorization: Bearer MY_PRIVATE_APP'​
    
  • HTTP 200
    
    {
     "results": [
     {
     "toObjectId": 1,
     "associationTypes": [
     {
     "category": "HUBSPOT_DEFINED",
     "typeId": 2,
     "label": "Primary Company"
     },
     {
     "category": "HUBSPOT_DEFINED",
     "typeId": 280,
     "label": null
     }
     ]
     },
     {
     "toObjectId": 51,
     "associationTypes": [
     {
     "category": "HUBSPOT_DEFINED",
     "typeId": 2,
     "label": "Primary Company"
     },
     {
     "category": "HUBSPOT_DEFINED",
     "typeId": 280,
     "label": null
     }
     ]
     },
     {
     "toObjectId": 101,
     "associationTypes": [
     {
     "category": "HUBSPOT_DEFINED",
     "typeId": 2,
     "label": "Primary Company"
     },
     {
     "category": "HUBSPOT_DEFINED",
     "typeId": 280,
     "label": null
     }
     ]
     },
     {
     "toObjectId": 201,
     "associationTypes": [
     {
     "category": "HUBSPOT_DEFINED",
     "typeId": 2,
     "label": "Primary Company"
     },
     {
     "category": "HUBSPOT_DEFINED",
     "typeId": 280,
     "label": null
     }
     ]
     },
     {
     "toObjectId": 251,
     "associationTypes": [
     {
     "category": "HUBSPOT_DEFINED",
     "typeId": 2,
     "label": "Primary Company"
     },
     {
     "category": "HUBSPOT_DEFINED",
     "typeId": 280,
     "label": null
     }
     ]
     },
     {
     "toObjectId": 351,
     "associationTypes": [
     {
     "category": "HUBSPOT_DEFINED",
     "typeId": 2,
     "label": "Primary Company"
     },
     {
     "category": "HUBSPOT_DEFINED",
     "typeId": 280,
     "label": null
     }
     ]
     }
     ]
    }
    

Thank you! — Jaycee

Hey Jaycee,

Thanks for your help !!

Here is the request that I do :

hubspotClient.crm.companies.associationsApi
 .getAll(event.object.objectId, 'contact')
 .then(results => {
 if (results.body.results.length == 0) {
 console.log("Company doesn't have any associated contacts");
 return;
 }

 let contactResults = results.body.results
 console.log(contactResults)
)

If I use Postman I get the same issue..

https://api.hubspot.com/crm/v3/objects/company/:company_id/associations/contacts

I only recover one contact..

It seems to filter randomly contacts that are associated… that’s pretty weird.

When there are actually 5 associated :

Any ideas ? Thanks for your help !!!

Have a nice day !

Amandine

I’m running into a similar issue.
If you’ve found a solution I’d be grateful to hear it!
I believe the problem is that the associationsApi.GetAll function only returns contacts that use this company as their Primary Company.
The documentation seems to suggest that there’s a way to remove that requirement by filtering for Unlabelled Contacts, which would truly return all Contacts, but I can’t see any specific way to add such a parameter.
I’ve also found other community responses suggesting that the Beta V4 version of the API will do this by default and filter for Primary as the more specific case, which would be ideal for me.