Create task doesn't add association

VStruyf
Contributor | Elite Partner
Contributor | Elite Partner

Hi,

 

I want to create a new task with an association with the api (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.

 

 

        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?

0 Upvotes
3 Replies 3
CClark04
Participant

@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 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.

0 Upvotes
Jaycee_Lewis
Thought Leader

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





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes
VStruyf
Contributor | Elite Partner
Contributor | Elite Partner

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}
0 Upvotes