Associations

Stacksync support syncing your HubSpot Associations in real-time 🚀

TL;DR

  • Stacksync supports two-way sync for HubSpot associations 🎉

  • Associations are undirected, meaning that if object A is associated with object B, object B is also associated with object A in return.

  • Associations cannot be updated, but you can delete and create a new one.

  • You can add several associations (with different association labels) to the same pair of objects.

  • Associations between ALL synced objects are supported, including emails, meetings, engagements, all standard and custom objects...

  • Associations for custom objects are also supported ✅

How HubSpot associations work

To associate two objects in HubSpot, you need to sync and use a third table "the association table" which contains in each row both of the object_ids to associate (e.g. associating a contact_id and a company_id).

When you connect two objects in HubSpot, the connection is undirected. If Contact A is connected to Company X, then Company X is also connected to Contact A in return.

To specify the type of connection between two objects, you can utilize association labels. For instance, Contact A can be labeled as a manager at Company X and also as a director at Company Y. In this case, you would connect Contact A with both companies but assign different labels to each connection.

Example of HubSpot associations: the same Contact is associated with two different Companies, each with different roles.

You can add several labels to the same pair of objects. For instance, Contact A can be in the finance_department and in the marketing_department of the same company. For that, you can add two rows for the same pair of objects but with different association labels as follows:

Stacksync ensures that all associations between pairs of object types are synchronized to an associative table. For example, any connection between a Contact and a Company will be synced to the "associations_company_and_contact" table, which has the following 3 columns:

  • contact_id (string)

  • company_id (string)

  • association_label (string)

There will be an additional column stacksync_record_id_xxxxxx. Don't worry, this column is just used by Stacksync to keep your records syncing properly. Just do not tamper this column!

Because HubSpot associations are undirected, these associations will only appear in one table. If you have a table associations_company_and_contact, there won't be a table with the opposite order (associations_contact_and_company).

Associations cannot be updated. Instead, you can delete and then create an association between the two desired objects with a different label.

Association Labels

HubSpot provides a set of predefined association types (e.g. unlabeled contact to company), but users can define custom association labels, if it is included in their HubSpot plan. There are two HubSpot-defined association types:

  • Primary: the main record that the other record is associated with. Default company association types include an unlabeled association type and a primary association type. If a record has more than one associated company, only one can be the primary company. The other associations can either be unlabelled or have custom association labels..

  • Unlabeled: an association type added when any contact, company, deal, ticket, or custom object record is associated. This type denotes that an association exists, and the association label will be fromObject_to_toObject_unlabeled. When a record has a primary association or a custom association label, those types will be listed alongside the unlabeled association type.

Read more on the HubSpot documentation here.

Querying your data

You can JOIN your data using the associations tables as follows:

SELECT
  -- Contact data
  contact.id, contact.email,
  -- Company data
  company.id, company.city,
  -- Association label
  associations.association_label
FROM (SELECT DISTINCT company_id, contact_id FROM hubspot.associations_company_and_contact) associations
LEFT JOIN hubspot.company company ON company.id = association.company_id
LEFT JOIN hubspot.contact contact ON contact.id = association.contact_id;

In this particular example, Contact and Company are used, but the principles mentioned can be applied to any other HubSpot CRM objects that can be synced with Stacksync. Suppose you have the custom Pets and custom Shelters objects in HubSpot. In that case, Stacksync will synchronize an associations_pets_and_shelters table, including the pet_id and shelter_id columns.

Last updated