The model: two categories, two very different kinds of ID
An association in HubSpot is not just a link between two records; it is a link of a particular type, and that type is identified by a numeric associationTypeId plus an associationCategory. HubSpot's own built-in relationships use the category HUBSPOT_DEFINED with a small fixed set of well-known IDs that are the same in every portal — contact-to-deal is typeId 4, for example, wherever you look.
Any label a portal admin creates under object association settings belongs to the category USER_DEFINED, and its numeric ID is allocated by that portal. "Decision Maker" might be typeId 35 in one account and 41 in another. This is the single fact that breaks most association integrations: a value that works perfectly in the developer's test portal is meaningless in the customer's.
Direction matters too. The association from contacts to deals is a different type ID from the association from deals to contacts, so the labels endpoint has to be called for the object pair in the order your write actually uses.
HUBSPOT_DEFINED vs USER_DEFINED association types
| Aspect | HUBSPOT_DEFINED | USER_DEFINED |
|---|
| Who creates it | HubSpot, built into the object pair | A portal admin, as a label |
| Is the numeric ID portable? | Yes — identical in every portal | No — allocated per portal |
| Safe to hardcode? | Yes | Never — must be looked up |
| label field in the API response | null | The label text shown in the UI |
Look the type ID up from the portal that will run the workflow
One GET against the labels endpoint for the object pair returns every association type available between those two objects, each with its typeId, its category and, for custom labels, the human-readable label text. Match on that label text, take the typeId, and cache it — the value only changes when an admin edits the association configuration, so fetching it per record wastes rate-limit budget to learn something that did not move.
GET https://api.hubapi.com/crm/v4/associations/contacts/deals/labels
Authorization: Bearer pat-na1-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
{
"results": [
{ "category": "HUBSPOT_DEFINED", "typeId": 4, "label": null },
{ "category": "USER_DEFINED", "typeId": 35, "label": "Decision Maker" },
{ "category": "USER_DEFINED", "typeId": 37, "label": "Influencer" }
]
}
# Needs read scope on BOTH objects in the pair.
# Cache the result. Do not call this per record.
Writing the association with that ID
The association call is separate from creating either record — both record IDs must already exist. The v4 endpoint takes an array, because a single pair of records can legitimately carry more than one association type at once, for example HubSpot's default relationship plus a custom label.
Send the category that matches the ID. Pairing USER_DEFINED with a HubSpot-defined ID, or the reverse, is the most common 400 on this endpoint, and it is easy to produce by copying a snippet that used the other category.
PUT https://api.hubapi.com/crm/v4/objects/contact/12345/associations/deal/98765
Authorization: Bearer pat-na1-xxxx...
Content-Type: application/json
[
{ "associationCategory": "USER_DEFINED", "associationTypeId": 35 }
]
# For many pairs at once, use the batch endpoint instead of a loop:
POST https://api.hubapi.com/crm/v4/associations/contacts/deals/batch/create
{
"inputs": [
{ "from": { "id": "12345" }, "to": { "id": "98765" },
"types": [ { "associationCategory": "USER_DEFINED", "associationTypeId": 35 } ] }
]
}
The failure mode that produces no error
A wrong-but-valid typeId does not fail. HubSpot creates an association of whatever type you named, so the API returns success, the workflow reports success, and the record shows a relationship — just not the one the business asked for. Nothing downstream will flag it, because there is no error to catch.
The only reliable verification is reading the association back, or opening the record in HubSpot and confirming the panel shows the intended label text rather than a generic association. Do that once against a disposable test pair before the workflow touches production records, and again after any portal migration, because the USER_DEFINED IDs in the new portal will not match the old ones.
Hardcoding a USER_DEFINED typeId is not a shortcut that occasionally breaks. It is guaranteed to apply the wrong label in any portal other than the one it was copied from, and to do so silently.
Reading associations back, and cleaning up the wrong ones
Because a wrong type ID produces no error, verification has to read the association rather than trust the write. The v4 read returns every association between a record and a given object type, each with the type IDs attached, so one GET tells you both that the link exists and which label it carries. That is the assertion worth leaving in the workflow for the first production cycle after any change to the lookup logic.
The read also surfaces the other thing that surprises people: a pair of records frequently carries more than one association at once. HubSpot's default relationship is often created alongside a custom label — by the built-in node, by a user working in the UI, or by an earlier version of the workflow — so a record showing the correct label may also be carrying a stale one that nobody intended.
Removing an unwanted association is a separate call from creating the right one, and it takes the same type ID and category. Work from the read rather than assuming what is there: deleting a HUBSPOT_DEFINED association that some other process depends on is easy to do by pattern and hard to notice afterwards.
# What is actually linked, and with which labels
GET https://api.hubapi.com/crm/v4/objects/contact/12345/associations/deal
Authorization: Bearer pat-na1-xxxx...
# -> { "results": [
# { "toObjectId": 98765,
# "associationTypes": [
# { "category": "HUBSPOT_DEFINED", "typeId": 4, "label": null },
# { "category": "USER_DEFINED", "typeId": 35, "label": "Decision Maker" }
# ] } ] }
# Remove only the specific labelled association, not the whole link:
POST https://api.hubapi.com/crm/v4/associations/contacts/deals/batch/labels/archive
{ "inputs": [ { "from": { "id": "12345" }, "to": { "id": "98765" },
"types": [ { "associationCategory": "USER_DEFINED",
"associationTypeId": 37 } ] } ] }
Where these facts come from