APIs & Integrations

mandou13
Participant

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

mandou13_0-1659433008297.png

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

mandou13_1-1659433137023.png

 

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

 

Thanks

0 Upvotes
3 Replies 3
Jaycee_Lewis
Community Manager
Community Manager

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

Hi, @mandou13 👋 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)
    company-contact-test-01.png
  • 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

 

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
mandou13
Participant

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

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

mandou13_0-1659512399526.png

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

When there are actually 5 associated :

Screenshot 2022-08-03 at 09.41.09.png

Any ideas ? Thanks for your help !!!

 

Have a nice day !

 

Amandine

0 Upvotes
RGoswell
Member

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

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.

0 Upvotes