X Enterprises
fastify-xhubspot

contacts.getAssociations / contacts.associate

Read and create associations between a HubSpot contact and other CRM objects.

contacts.getAssociations / contacts.associate

Read all associations of a given type for a contact, or create a new association between a contact and another CRM object.

Signatures

fastify.contacts.getAssociations(
  contactId: string,
  associationType: string
): Promise<Array<{ id: string; type: string }>>

fastify.contacts.associate(
  contactId: string,
  objectId: string,
  associationType: string
): Promise<true>

Params

getAssociations

NameTypeRequiredDescription
contactIdstringYesHubSpot contact ID.
associationTypestringYesAssociation type label, e.g., "companies", "deals", "tickets".

associate

NameTypeRequiredDescription
contactIdstringYesHubSpot contact ID.
objectIdstringYesID of the object to associate the contact with.
associationTypestringYesAssociation type label, e.g., "companies", "deals".

Returns

getAssociations

Array of { id, type } for each associated object.

associate

true on success.

Throws

  • [xHubspot] contacts.getAssociations requires a contactId — if missing.
  • [xHubspot] contacts.getAssociations requires an associationType — if missing.
  • [xHubspot] contacts.associate requires a contactId/objectId/associationType — on missing args.
  • Re-throws HubSpot API errors.

Examples

getAssociations — get all deals for a contact

const deals = await fastify.contacts.getAssociations("12345", "deals");
// [{ id: "67890", type: "CONTACT_TO_DEAL" }, ...]
fastify.post("/contacts", async (request, reply) => {
  const contact = await fastify.contacts.create(request.body.contact);
  const company = await fastify.contacts.associate(
    contact.id,
    request.body.companyId,
    "companies"
  );
  return reply.code(201).send({ contactId: contact.id });
});

See also

AI Context

package: "@xenterprises/fastify-xhubspot"
methods: fastify.contacts.getAssociations(contactId, toObjectType) | fastify.contacts.associate(contactId, toObjectId, toObjectType)
use-when: Read or create associations between a contact and another HubSpot CRM object (deal, company, etc.)
returns: getAssociations → { results } | associate → void
Copyright © 2026