Get all contacts - where is companyid?


#1

Hi there,

I’m using the “Get all contacts” method to retrieve all contacts but in the json response the companyid property doesn’t exists, Where is it?

First, I have to invoke the “Get all contacts” method and then the “Get a Contact Property” to get the companyid property value?

I need the companyid property in the “Get all contacts” method to associate the contact to the company in my CRM. I wouldl’n like to invoke two methods.

Another way to do this would be to call the “Get contacts of a company” method for each of the companies I have but I think this is much worse.

Thanks in advance.


#2

i’m pretty sure you have to get all contacts, then iterate through them and make a call for each contact individually to get the full list of contact properties, including the companyId.

so first you need to run…
https://api.hubapi.com/contacts/v1/lists/all/contacts/all?hapikey=[APIKEY]

and then on each one, you pull the individual profile. to make it slightly less data, you can specify the property you want, as well as strip out form submission and list membership data, as well as prior property values, like so…
https://api.hubapi.com/contacts/v1/contact/vid/1/profile?hapikey=[APIKEY]&property=associatedCompanyId&propertyMode=value_only&formSubmissionMode=none&showListMemberships=false

it would be nice if they included a bit more data in the get all contacts functionality, but for now i think this is the answer.


#3

Hi @aperez

The contact property you’re looking for is associatedcompanyid, which would contain the companyId of the company record associated with the contact.

When pulling all (or recently updated) contacts, you can include specific properties in the response using the property= parameter. The following example would return the email and associatedcompanyid for all contacts:

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

#4

nice! i thought you had to iterate these… :slight_smile:


#5

Hi,
first of all, thanks for your fast response.
The solution of @dadams is perfect, this way I get what I want with a single request :slight_smile:


#6

@dadams How to get Phone Number and Name of Contacts? In my JSON response i am just receiving email of contacts.


#7

I am using @dadams query, However, I am getting all the mentioned properties except associatedcompanyid.

I know in my hubspot account, I have company and contacts associated together .

For example if I add property=firstname and property=lastname property I will see changes, but when I add property=associatedcompanyid, I dont see them pop up. Is there any reason for this?

https://api.hubapi.com/contacts/v1/lists/all/contacts/all?property=email&property=lastname&property=firstname&property=associatedcompanyid