APIs & Integrations

Dan_Potts
Member

Include Company ID in Contacts List

SOLVE

I'm exporting data using the API. I'm fetching a list of all Companies, and all Contacts. I'd like to then join the two lists to pair up Contacts with their Company; however, I have a number of Companies that have the same name so the join is failing.

The only way to do this efficiently would be to join by Company ID.

  1. Can I get the Company ID when using this endpoint?
  2. If not, how can I efficiently match these two objects?

Thanks!

0 Upvotes
1 Accepted solution
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Include Company ID in Contacts List

SOLVE

Hey, @Dan_Potts.

You're totally right; there's a better way!

The contact property associatedcompanyid stores the associated companyId value, so you could just use this variation of the Get all contacts endpoint:

https://api.hubapi.com/contacts/v1/lists/all/contacts/all?property=associatedcompanyid

I just tested and confirmed it returns the correct companyId values along with the records!

Isaac Takushi

Associate Certification Manager

View solution in original post

4 Replies 4
Dan_Potts
Member

Include Company ID in Contacts List

SOLVE

AMAZING! You nailed it. This is exactly what I was looking for! Thank you so much!

IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Include Company ID in Contacts List

SOLVE

Hey, @Dan_Potts.

You're totally right; there's a better way!

The contact property associatedcompanyid stores the associated companyId value, so you could just use this variation of the Get all contacts endpoint:

https://api.hubapi.com/contacts/v1/lists/all/contacts/all?property=associatedcompanyid

I just tested and confirmed it returns the correct companyId values along with the records!

Isaac Takushi

Associate Certification Manager
IsaacTakushi
HubSpot Employee
HubSpot Employee

Include Company ID in Contacts List

SOLVE

Welcome, @Dan_Potts!

It sounds like the CRM Associations API may be what you're looking for.

Specifically, you can retrieve the company IDs associated with a given contact by using this endpoint and definitionId 1.

Isaac Takushi

Associate Certification Manager
0 Upvotes
Dan_Potts
Member

Include Company ID in Contacts List

SOLVE

Thanks for your response, Isaac!

So when I get my list of Contacts, to get the Company ID associated with that Contact, I have to request the 'Get associations for CRM object' for each Contact. E.g. If I have 5000 Contacts, to get the ID of the Company each one belongs to, I have to make 5000 requests?

Is there a more efficient way that this can be accomplished?

0 Upvotes