Create a Custom Object with associations

I’m trying to create an item in an object that is already associated with a contact…

My endpoint: https://api.hubapi.com/crm/v3/objects/financeiro

My body:
{
“properties”: {
“nome”: “Fatura - 27625 - CTE24371/37913”,
“hs_pipeline”: “147734376”,
“hs_pipeline”: “636407452”,
“cnpj”: “29951608000183”,
“codigo_pn”: “4092650”,
“valor_da_fatura”: “295.25”,
“valor_pago”: “0”,
},
“associations”: [
{
“to”: {
“id”: 76665984395
},
“types”: [
{
“associationCategory”: “HUBSPOT_DEFINED”,
“associationTypeId”: 16
}
]
}
]
}

However, the HubSpot API returns an error:

invalid from object type 2-36186255 for associations to be created. expected: 0-5

I can’t identify what the error is and how to fix it. Can you help me?

Hi @flpeSouza and welcome to the Community, it’s a pleasure to have you here!
Thanks for asking us!
I have found this similar post “Custom Objects & Associations API v4” where the solution from @LMeert might help you!
Also, I’d love to put you in touch with some of our Top Experts: Hi @Bortami, @HubSpot_Corey and @ChrisoKlepke do you have suggestions to help @flpeSouza, please?
Thanks so much and have a great day!
Best,
Bérangère

The error is telling you that you need to include the correct associationTypeId and associationCategory.

associationCategory: HUBSPOT_DEFINED and associationTypeID: 16 is the Ticket to Contact associations. (list of HubSpot Defined associations here)

To get the correct association category and type id, you can view the API details in the UI (Settings > Objects > Associations) or by calling /crm/v4/objects/{objectType}/{objectId}/associations/{toObjectType}