Guides / n8n × HubSpot / Associations

HubSpot association errors: getting the associationTypeId right

Why an association call succeeds and still produces the wrong relationship, how HUBSPOT_DEFINED and USER_DEFINED type IDs differ, and the one lookup that makes custom labels portable across portals.

FlowPatch diagram: Object pair to association label to type ID. Read the current association schema.
400 — "Invalid input JSON... associationTypeId" on a v4 association call, or no error at all and the wrong (default) label appears on the record.
Short answer: Every HubSpot association carries an associationTypeId belonging to one of two categories. HUBSPOT_DEFINED IDs are fixed and identical in every portal; USER_DEFINED IDs belong to custom labels an admin created and are specific to that one portal, so they can never be hardcoded from documentation or copied between accounts. Look the ID up once from /crm/v4/associations/{from}/{to}/labels, cache it, and send it with the matching associationCategory — a wrong ID usually does not error, it silently applies the wrong relationship.

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

AspectHUBSPOT_DEFINEDUSER_DEFINED
Who creates itHubSpot, built into the object pairA portal admin, as a label
Is the numeric ID portable?Yes — identical in every portalNo — allocated per portal
Safe to hardcode?YesNever — must be looked up
label field in the API responsenullThe 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