APIs & Integrations

kcal0
Member

limiting which association types return with company, using PHP (api v3)

I am using the PHP api.  I just want a list of companies, thier names / ids, and if they are a child or parent / who is their parent.  Here is the code I am experimenting with..

 

$companies = $hubspot->crm()->companies()->basicApi()->getPage(100, null, ['name'], null, ['companies'])->getResults()

 

This does return the companies and associations but it is way way more data then I need.  I do not want any other associations returned.   I am finding the documentation on this lacking.  The PHP api library appears to append "?associations=companies" to the end of the request which causes them to be included in the page data.  The issue I am having is I get a lot more (custom) associations with it, when I only want the types:

child_to_parent_company

and

parent_to_child_company


I was hoping there may be a secret syntax not well documented such as.. associations=companies|child_to_parent_company

Any suggestions?

0 Upvotes
5 Replies 5
skimura
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

limiting which association types return with company, using PHP (api v3)

  

@kcal0 

Hi.

 

How about try this? (not tested)

$associations = [ 'child_to_parent_company', 'parent_to_child_company', ];
$companies = $hubspot->crm()->companies()->basicApi()
  ->getPage(100, null, ['name'], null, $associations)->getResults();

// if not working, try below.
//
// 1.
// $associtations = ['child_to_parent_company,parent_to_child_company'];
//
// 2. I'm using an older version and in this case the below works
// $associtations = [
//   'associations' => 'child_to_parent_company,parent_to_child_company',
// ]; 

 

References:

https://developers.hubspot.com/docs/api/crm/companies

GET /crm/v3/objects/companies

List

Parameters → open [see all params]

associataions [arrayQuery param]

A comma separated list of object types to retrieve associated IDs for. If any of the specified associations do not exist, they will be ignored.

 

Source code:

https://github.com/HubSpot/hubspot-api-php/blob/master/codegen/Crm/Deals/Api/BasicApi.php#L1161

 

I hope this helps.

Thanks.

 

@Jaycee_Lewis

thanks for metion.

kcal0
Member

limiting which association types return with company, using PHP (api v3)

Thank you @skimura  for the suggestion, I tried all 3 combinations (string, array 2 options, array 1 option using a comma in string) and I get same error each time...

Unable to infer object type from: child_to_parent_company

 

If this worked for you on an older version maybe I could try downgrading.

0 Upvotes
skimura
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

limiting which association types return with company, using PHP (api v3)

@kcal0 

>Unable to infer object type from: child_to_parent_company

The following might help as it's the same error message.

https://community.hubspot.com/t5/APIs-Integrations/Custom-Object-Association-Issue-quot-Invalid-inpu...

 

*In my case, checked associate ticket and line items from deals.

 

 

 

0 Upvotes
kcal0
Member

limiting which association types return with company, using PHP (api v3)

@skimura  Thank you for the suggestion... that discussion is about using the type id from the schema, I tried that (id 13, 14) and getting the same error.

 

Unable to infer object type from: 13

 

To me it seems that the associations parameter requires an object type specified (in this case: company), but does not work with association types (e.g. child_to_parent_company).  I would prefer to specify the association type so I can exclude associations I am not working with from the api response but it is rejecting anything but object types.

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

limiting which association types return with company, using PHP (api v3)

Hi, @kcal0 👋 Thanks for your question. I'd like to invite some of our community experts who have experience with PHP — hey @skimura @JBeatty @danhammari do you have any suggestions for @kcal0?

 

Thank you very much! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes