Hi,
I’m using Hubspot’s Python API to retrieve deal data from the CRM. I want to get the company ID associated with each deal (if there’s any) but I’m running into API errors.
I noticed that function client.crm.deals.basic_api.get_page() has a parameter called ‘associations’ - which I presume, if used, would include the required associations data in the API response data.
I’ve tried looking for documentation online on how this ‘associations’ argument can be defined within get_page() but I couldn’t find any information. I’ve tried using associations=“company”, associations=“companies” but that results in the API call erroring out (“Unable to infer object type from: c”)
I’m currently using a separate API call to get the deal-to-company association (
using client.crm.associations.batch_api.read) but it would be way better if I could get the associations data without a separate API call
Any advice highly appreciated!
Hello @andriushivehr thank you for posting in our Community!
I want to share this page with more information about associations.
To our top experts @TomAshford @coldrickjack @zach_threadint any recommendations to @andriushivehr matter?
Thank you,
Pam
Hi @andriushivehr 
(thanks for the nudge @PamCotton
)
The “associations” argument within HubSpot’s Python API client’s get_page() method requires a list data type. For example:
api_response = client.crm.deals.basic_api.get_page(associations=["companies"])
Keep in mind it’s only possible to return the associated record ID(s) using this feature. You’ll still need to make another request to the Companies API to retrieve any required information stored within the associated Company record.
I hope this proves useful. Please let me know if you have any follow-up questions.
Thank you @zach_threadint , this does exactly what I need 
Hi - I have one more question. Do you have any idea why I could be getting the same association ID returned twice under different association types (labelled/unlabeled)? Below is the API response:
‘associations’: {‘companies’: {‘paging’: None,
‘results’: [{‘id’: ‘HIDDEN’,
‘type’: ‘deal_to_company’},
{‘id’: ‘HIDDEN’,
‘type’: ‘deal_to_company_unlabeled’}]}},
Hi @andriushivehr 
Based on some quick testing, association type “deal_to_company” will always represent the “Primary” associated Company. If a “Primary” association has not been defined, this will not be returned by the API. In addition, it’s also possible for the record associated as the “Primary” to have a custom association label. As such, the API will also return an association relevant to the custom label feature (in your case, the association is “unlabeled”).
I hope this proves useful. Please let me know if you have any follow-up questions.
That’s great, thank you so much for the quick reply 