APIs & Integrations

danhammari
Contributeur

api v3 associations: are constants defined for "associationType"?

Résolue

I have been searching through the API v3 documentation but have not been able to find a list of valid strings that would satisfy the associationType parameter in the HubSpot CRM objects API. In particular, I am using the endpoint below to associate a deal with a company:

 

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

PUT /crm/v3/objects/deals/{dealId}/associations/{toObjectType}/{toObjectId}/{associationType}
 
The PHP library defines constants that satisfy the requirements for the toObjectType parameter:

namespace: HubSpot\Crm

    class: ObjectType

  example: \HubSpot\Crm\ObjectType::DEALS

 
However, I am unable to find any constants in the PHP library that may help with the associationType parameter. I can guess that the string I need will be something like "deal_to_company" but would rather not have to guess.
 
This is the PHP API that I am trying to implement:

namespace: HubSpot\Client\Crm\Deals\Api

    class: AssociationsApi

  method: create( $deal_id, $to_object_type, $to_object_id, $association_type, $paginate_associations = false );

 
Could anyone point me to where I can find an official list of standardarized values for the association types that API v3 expects?
0 Votes
1 Solution acceptée
danhammari
Solution
Contributeur

api v3 associations: are constants defined for "associationType"?

Résolue

The Associations API v3 has an endpoint that will allow you to query the system and ask what types of associations are available between a pair of CRM objects:

 

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

Types
GET /crm/v3/associations/{fromObjectType}/{toObjectType}/types

 

This API endpoint will return the identifiers for the assocation you are looking for.

Query:

GET /crm/v3/associations/contacts/companies/types

Response:

HTTP 200
{ "results": [ { "id": "1", "name": "contact_to_company" } ] }

 

Please note that the association returned is direction specific. You can get the id and name of the association type going the other direction by swapping the {fromObjectType} and {toObjectType} properties.

Query:

GET /crm/v3/associations/companies/contacts/types

Response:

HTTP 200
{ "results": [ { "id": "2", "name": "company_to_contact" } ] }

 

Voir la solution dans l'envoi d'origine

6 Réponses
MFloyd2
Participant

api v3 associations: are constants defined for "associationType"?

Résolue

For anyone who finds this question in 2023 or later, it appears that there is now a list:

https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview

0 Votes
danhammari
Solution
Contributeur

api v3 associations: are constants defined for "associationType"?

Résolue

The Associations API v3 has an endpoint that will allow you to query the system and ask what types of associations are available between a pair of CRM objects:

 

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

Types
GET /crm/v3/associations/{fromObjectType}/{toObjectType}/types

 

This API endpoint will return the identifiers for the assocation you are looking for.

Query:

GET /crm/v3/associations/contacts/companies/types

Response:

HTTP 200
{ "results": [ { "id": "1", "name": "contact_to_company" } ] }

 

Please note that the association returned is direction specific. You can get the id and name of the association type going the other direction by swapping the {fromObjectType} and {toObjectType} properties.

Query:

GET /crm/v3/associations/companies/contacts/types

Response:

HTTP 200
{ "results": [ { "id": "2", "name": "company_to_contact" } ] }

 

01009
Participant

api v3 associations: are constants defined for "associationType"?

Résolue

IMO this would really be helpful to be specified in the developer documentation for the custom objects page. https://developers.hubspot.com/docs/api/crm/crm-custom-objects

 

0 Votes
ph_alti_trading
Contributeur

api v3 associations: are constants defined for "associationType"?

Résolue

Hi @danhammari 

Looking at the page https://developers.hubspot.com/docs/api/crm/deals you provided, from the json response in the example the value "contact_to_company" is used. So yes, please go ahead and try "deal_to_company" 🙏

 

I don't think there is gonna be a list of standardarized values for the association types that API v3 expects, basically it's a "Discovery" like architecture.

In the case we can associate every object together, (Ref: https://github.com/HubSpot/hubspot-api-php/blob/master/lib/Crm/ObjectType.php) at the time of writing it would be 7 x 7 = 49 constants. In the previous version (Ref: https://github.com/HubSpot/hubspot-php/blob/master/src/Resources/CrmAssociations.php) there were already 46 constants. I think we can consider HubSpot drop the maintenance on such constants.

 

I can't tell you as I didn't test but looking at your previous ticket,in case the plural version is working ( 'deals_to_companies' ), you could might give a try with :
\HubSpot\Crm\ObjectType::DEALS . '_to_' . HubSpot\Crm\ObjectType::COMPANIES (or something similar)

If anyone has a feedback or opinion on the subject, you are welcome to share it the community 😃

 

Best of luck

 

danhammari
Contributeur

api v3 associations: are constants defined for "associationType"?

Résolue

I tried out your suggestion but it doesn't seem failproof.

 

For example, I tried the following:

$to_object_type = \HubSpot\Crm\ObjectType::COMPANIES;
$association_type = \HubSpot\Crm\ObjectType::CONTACTS . '_to_' . \HubSpot\Crm\ObjectType::COMPANIES;
$association_response = $hubspot_api_contact_helper->associationsApi()->create(
  $hubspot_contact_id,
  $to_object_type,
  $hubspot_company_id,
  $association_type
);

 

And received the following error:

{
  "message":"[400] Client error: `PUT https://api.hubapi.com/crm/v3/objects/contacts/88141351/associations/companies/2410836413/contacts_to_companies?paginateAssociations=&hapikey=XXX` resulted in a `400 Bad Request`"
}
{
  "response":{
    "status":"error",
    "message":"contacts_to_companies is not a valid association type between contacts and companies"
}

 

I manually changed the association type to "Contact_to_Company" and the API seemed to work.

It would be nice if we didn't have to guess at the values for these undocumented constants.

dennisedson
Équipe de développement de HubSpot
Équipe de développement de HubSpot

api v3 associations: are constants defined for "associationType"?

Résolue

Heyo @danhammari 

Throwing the usual cast of characters into this 😀

@quentin_lamamy , @philx , @AndrewFisher , @twnk , @ph_alti_trading any ideas? (and @ph_alti_trading , I know you are not using the v3 endpoints, but I like tagging you nonetheless 🙃)