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
| Name | Type | Required | Description |
|---|---|---|---|
contactId | string | Yes | HubSpot contact ID. |
associationType | string | Yes | Association type label, e.g., "companies", "deals", "tickets". |
associate
| Name | Type | Required | Description |
|---|---|---|---|
contactId | string | Yes | HubSpot contact ID. |
objectId | string | Yes | ID of the object to associate the contact with. |
associationType | string | Yes | Association 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" }, ...]
associate — link a contact to a company on creation
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
- companies.getAssociations — read associations from the company side
- deals.getAssociations — read associations on deals
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
