Hi,
I want to create a new task with an association with the api (Accounts Dashboard | HubSpot)
When I create it with the test call, the task is created with the association, but when I create a task with my code (node), the task is created without the association.
const properties = {
"hs_timestamp": "2023-10-30T03:30:17.883Z",
"hs_task_body": "test123",
"hubspot_owner_id": "....",
"hs_task_subject": "test 5",
"hs_task_status": "WAITING",
"hs_task_priority": "HIGH",
"hs_task_type": "TODO"
};
console.log(item.id);
const SimplePublicObjectInput = { properties, "associations": [{"to":{"id":"..."},"types":[{"associationCategory":"USER_DEFINED","associationTypeId":2}]}] };
return hubspotClient.crm.objects.tasks.basicApi.create(SimplePublicObjectInputForCreate);
or
return hubspotClient.crm.objects.basicApi.create("tasks", SimplePublicObjectInput);
both give the same result > a task without an association.
Anyone an idea what is going wrong?
Hey, @VStruyf
Thanks for your question. The first place I’d check is the typeId. For example, when associating a Task to a Contact, it’s
"typeId": 204
You can make a GET request to /crm/v4/associations/{fromObjectType}/{toObjectType}/labels to get the correct ID for the specific type and direction of your associations.
It might look like this:
const properties = {
"hs_timestamp": "2023-10-30T03:30:17.883Z",
"hs_task_body": "test123",
"hubspot_owner_id": "....",
"hs_task_subject": "test 5",
"hs_task_status": "WAITING",
"hs_task_priority": "HIGH",
"hs_task_type": "TODO"
};
console.log(item.id);
const SimplePublicObjectInput = {
properties,
"associations": [
{
"to": {
"id": "..."
},
"types": [
{
"associationCategory": "HUBSPOT_DEFINED",
"associationTypeId": 2
}
]
}
]
};
return hubspotClient.crm.objects.tasks.basicApi.create(SimplePublicObjectInput);
If you are not associating Tasks to Contacts, can you share with the community which associations you are making? And if they are default or custom association types?
Thank you for the additional information! — Jaycee
Hi,
I want to associate a task to a custom object and when I do the call to get the info I get this:
{"associationCategory":"USER_DEFINED","associationTypeId":2}
@VStruyf Did you ever resovle this? I’m in a similar situation, creating a deal and associating to a custom object via the v4 api.
When I use the create preview in the docs Accounts Dashboard | HubSpot it works fine, creating the deal and associating it correctly.
However when I use the generated code snippet in my serverless the association is simply not created.