# Create task doesn't add association

**URL:** <https://community.hubspot.com/t/create-task-doesnt-add-association/81002>\
**Category:** APIs & Integrations\
**Tags:** developer-tools\
**Created:** [May 11, 2023, 10:50am UTC](https://community.hubspot.com/t/create-task-doesnt-add-association/81002 "2023-05-11T10:50:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![VStruyf](https://avatars.discourse-cdn.com/v4/letter/v/46a35a/32.png) [@VStruyf](https://community.hubspot.com/u/VStruyf)\
**Post date:** [May 11, 2023, 10:50am UTC](https://community.hubspot.com/t/create-task-doesnt-add-association/81002/1 "2023-05-11T10:50:00Z")

</div>

Hi,

I want to create a new task with an association with the api ([Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/api/crm/tasks))

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.

```lia-code-sample
 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?

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [May 11, 2023, 8:06pm UTC](https://community.hubspot.com/t/create-task-doesnt-add-association/81002/2 "2023-05-11T20:06:25Z")

</div>

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](https://developers.hubspot.com/docs/api/crm/associations#:~:text=Retrieve%20association%20types) 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:

```lia-code-sample
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

---

<div class="post-metadata">

**Author:** ![VStruyf](https://avatars.discourse-cdn.com/v4/letter/v/46a35a/32.png) [@VStruyf](https://community.hubspot.com/u/VStruyf)\
**Post date:** [May 15, 2023, 7:50am UTC](https://community.hubspot.com/t/create-task-doesnt-add-association/81002/3 "2023-05-15T07:50:46Z")

</div>

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}`

---

<div class="post-metadata">

**Author:** ![CClark04](https://avatars.discourse-cdn.com/v4/letter/c/f07891/32.png) [@CClark04](https://community.hubspot.com/u/CClark04)\
**Post date:** [July 5, 2023, 9:17pm UTC](https://community.hubspot.com/t/create-task-doesnt-add-association/81002/4 "2023-07-05T21:17:09Z")

</div>

@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](https://developers.hubspot.com/docs/api/crm/deals) 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.
