How are Deals linked to Companies and Contacts (API)

Hi there.

I am using Python and the Hubspot package to extract companies, contacts, and deals from Hubspot.

When I extract deals, I see associations = None in the object data for each Deal.

but I see no companies attribute or contacts attribute in the data for each Deal.

I am exceptionally good at doing dumb things, so I presume this is on me :)… What am I doing wrong here?

Cheers

Jo

Hi @Jopitts,
Thank you for posting to the Community!
I am going to tag in some of our Top Contributors to see if they have any suggestions - @ChristinaKay @HubSpot_Corey and @Gonzalo Have you seen a case like this before?
Cassie, Community Manager

All,

further to this… when I use the same Python libary to extract contacts I don’t see which company they are associated with.

I am clearly missing something very obvious, but I have no idea what it is.

Actually.. you can ignore the question about contacts. I added associatedcompanyid to the properties and magically got what I wanted.

The question about Deals still remains.

Right. After much much much googling, I worked out the answer. You need to pass the associations = [] parameter into the API call. This will retrieve the association types you pass in.

In this case I passed associations = [‘companies’,‘contacts’] as got the data I needed.

Hi @Jopitts
You’re right when you call the Deals API, associations don’t come through by default.

You have to explicitly request them. The correct approach is to add the associations parameter in your call, for example associations=['companies','contacts'].

That way the API will include the linked company and contact IDs with each deal. HubSpot’s docs confirm this: ( Accounts Dashboard | HubSpot )

(Accounts Dashboard | HubSpot )

One small gotcha: if you’re working with large datasets, remember associations come with pagination and rate limits, so it’s safer to batch in chunks of 100 and respect the 10 requests/second cap.

And since you mentioned wrestling with associations, some teams simplify this whole part by using a sync layer that keeps HubSpot objects and external databases aligned automatically.

A platform like Stacksync does exactly that, handling deal-company-contact links in real time so you don’t need to wrangle the association logic yourself.

Hope this clears things up.