X Enterprises
fastify-xhubspot

companies.getAssociations

Read all associations of a given type for a HubSpot company.

companies.getAssociations

Get all CRM objects associated with a HubSpot company by association type.

Signature

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

Params

NameTypeRequiredDescription
companyIdstringYesHubSpot internal company ID.
associationTypestringYesAssociation type label, e.g., "contacts", "deals".

Returns

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

Throws

  • [xHubspot] companies.getAssociations requires a companyId
  • [xHubspot] companies.getAssociations requires an associationType
  • Re-throws HubSpot API errors.

Examples

Get all contacts for a company

const contacts = await fastify.companies.getAssociations("98765", "contacts");
// [{ id: "12345", type: "COMPANY_TO_CONTACT" }, ...]

Enrich a company with its contacts

fastify.get("/companies/:id/team", async (request) => {
  const associations = await fastify.companies.getAssociations(
    request.params.id,
    "contacts"
  );

  const contactIds = associations.map(a => a.id);
  const contacts = await Promise.all(
    contactIds.map(id => fastify.contacts.getById(id))
  );

  return contacts.map(c => ({
    id: c.id,
    name: `${c.properties.firstname} ${c.properties.lastname}`,
    email: c.properties.email,
  }));
});

See also

AI Context

package: "@xenterprises/fastify-xhubspot"
method: fastify.companies.getAssociations(companyId, toObjectType)
use-when: Read associations between a company and another HubSpot CRM object (contact, deal, etc.)
returns: { results }
Copyright © 2026