Retrieve list of Contacts with their primary Company

Hello everyone!

I’m new to the community, just getting started with Hubspot.

We are creating a custom integration in which I need to retrieve all the contacts belonging to a “Contacts List”, with their companies, like:

- firstname

- lastname

- email

- company name

- company website

I’m using the “Contacts List API V1” with no problem, but I can’t get the associated properties from the Company.

I read somewhere that we have access to those associated properties in the CRM Search, so I’m grabbing all the emails I get from the first response and now querying the Search API V3, with a “email IN […]” filter, like this:

```

body = {

filterGroups:

[

{

filters: [

{

values: emails,

propertyName: “email”,

operator: “IN”

}

]

}

],

properties: [“email”, “state”, “associatedcompanyid”]

}

```

but I just get the ID of each company… will I need to do a third search in Companies?

I can’t believe this is the best way of doing it… there must be another smarter way.

Thanks!

Hi @heytavo :waving_hand:

Welcome to the community :slightly_smiling_face:

I suggest the following approach:

Request 1

Call the “Get contacts in a list” endpoint, while using an instance of the “property” query parameter to retrieve the given Contacts’ "associatedcompanyid" property value (this is a hidden Contact property, which you may not have come across yet). Your request URL should look something like this:

You should then have all Company record IDs relevant to the given Contacts.

Request 2

Call the “Read a batch of companies” endpoint, specifying the Company IDs and the properties to be returned in the request body. Your request body might look something like this

(substitute the placeholders with your target Company properties)

:

{
 "properties": [
 "name",
 "domain",
 "state",
 "country"
 ],
 "inputs": [
 {
 "id": "123"
 },
 {
 "id": "456"
 }
 ]
}

Where “123” and “456” are example Company record IDs, returned from the first request.

You should then have all the information you need for your described use case :crossed_fingers:

I hope this proves useful. Please let me know if you have any follow-up questions.

Thank you very much, Zach. It worked!

I wasn’t aware of that associatedcompanyid property. Is it going to be the primary one?

@heytavoHappy to help :slightly_smiling_face:

Yes, the associatedcompanyid will reflect the Company that is marked as the “Primary” association. The property description provided by HubSpot is: “HubSpot defined ID of a contact’s primary associated company in HubSpot.”

Great, thanks!

Super helpful, been looking through the forums for a few days for the “associatedcompanyid” property value.