Include Company ID in Contacts List


#1

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!


#3

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.


#4

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?


#5

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!


#6

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