Get list of company that is associated with Deals

Hi,

I am currently using Hubspot API and currently exploring the following:

Is it possible to get list of companies that is associated with Deals?

Or maybe is it possible to get list of companies based on companyIds? E.g. /companies?companyIds=1&companyIds=2

Hi @nedoffs,

I hope all is well with you :grinning_face_with_smiling_eyes:

While there isn’t a single endpoint to get a list of companies that is associated with Deals, I’d suggest for you to use the Get all companies API and Get associations for CRM object API:

  • When using the Get all companies API, include the &properties=num_associated_deals property so that the return results will include the value of the number of associated deals for the companies record. If there’s no associated deals, the value will be “”.
  • Knowning this, you can loop through the return results and only retrieve the companyId that has num_associated_dealsvalue known.
  • Next, include the companyId retrieved in our earlier steps and include it on the url of Get associations for CRM object API with a definition id of 6 (Association definition); this will retrieve all the dealId for that particular company record.

Currently, it is not possible to get multiple companies record by companyIds.

Hope this helps to clarify!

Hi@WendyGoh ,

I have a similar issue where I am trying to retrieve the company ids via the get all companies endpoint. But I am getting an error everytime I try. The json response for the company Id is below (sensitive data removed off course):

{companies=[{companyId=xxxxxxxxxxxxE9,

 response.companies.forEach(function(item) {

 var companyId = (item.companies.hasOwnProperty('companyId')) ? item.companies.companyId : 'NA' ;

The error is a TypeError: Cannot call method "hasOwnProperty" of undefined. (line 62, file "getCompanies.js")

But this works for the get all deals endpoint, so I am wondering what is wrong.

Thanks,

Kawyn

Hi @kawyns1,

It looks like the internal id for the company id property is hs_object_id(Settings > Properties > Company properties > Search for ‘Company ID’ > Click in > Check the internal name)

This is likely why when you use companyId to store the var companyId property, it is throwing an error.

Hi @WendyGoh ,

Thank you, this worked. I actually do have a question about the marketing emails API, but I will ask it on a different post.

Regards,

Kawyn