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
| Name | Type | Required | Description |
|---|---|---|---|
companyId | string | Yes | HubSpot internal company ID. |
associationType | string | Yes | Association 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
- contacts.associate — create an association from the contact side
- contacts.getAssociations — read associations from a contact
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 }
