Get company id for every deal

Please advise - I need to get the associated companies’ IDs for chosen deals.

Here is the URL:

POST https://api.hubapi.com/crm/v3/objects/deals/search

And the body:
filters = [
{ "propertyName": "dealstage", 
 "operator": "IN", 
 "values": stage_ids }
] 

if owner_ids: 
filters.append(
{ "propertyName": "hubspot_owner_id", 
"operator": "IN", 
"values": owner_ids 
}) 

payload = 
{ 
"filterGroups": 
[{ "filters": filters }], 
"properties": 
["dealstage", "dealname", "pipeline", "associatedCompanyId"], 
"associations": ["company"] 
}

And in the response, I don’t receive associatedCompanyId or other information about the company.

I know that I can use Associations API to get company info like this:

url = f"https://api.hubapi.com/crm/v3/objects/deals/{deal_id}/associations/company

But in this case, I’d need to do it for every deal, which I don’t want to do. Please advise.

Hi, @idunskiy :waving_hand: You are correct about the limitations of the Search API. You’ll have to make a second request to the Associations API to get what you are after. Unfortunately, there is not a unified endpoint that will do everything you want in a single call.

Best,

Jaycee

Unless you create a GraphQL query :tada:

Here is a great blog from Carter: Reducing HubSpot Requests: Utilizing Batch API and GraphQL for Better Optimization

It is limited to Sales/Service Hub Enterprise or Content Hub Pro.

Hey, @Teun :waving_hand: Great point. The issue here is, this customer doesn’t have either of those subscriptions. — Jaycee