Creating a task and associating to contact and company

Hi, I am currently trying to create a task and associate it with a contact and company using the endpoint

https://api.hubapi.com/crm/v3/objects/tasks
The problem I’m facing is that according to the Associations v4 documentation, to associate an object with contact, the code is 203, but in the example request in the Tasks documentation, for associate it with a contact it uses 204.
If I use 203 the endpoint response is:

{

"status": "error",

"message": "invalid from object type 0-27 for associations to be created. expected: 0-2",

"correlationId": "295599d8-2f54-4b18-b727-45764445aa1a",

"category": "VALIDATION\_ERROR"

}
If I use 204, it creates the task perfectly, so the error may be in the Associations v4 documentation.

My current request is this, I am getting the same error as before, and I think the reason is the code 191 for company, it should be another code.

{

“properties”: {

 "hs\_timestamp": "2023-07-12T13:30:17.883Z",

 "hs\_task\_body": "trying to execute this endpoint",

 "hubspot\_owner\_id": "165887603",

 "hs\_task\_subject": "Talk to an executive",

 "hs\_task\_status": "NOT\_STARTED",

 "hs\_task\_priority": "HIGH",

 "hs\_task\_type":"TODO"

},

“associations”: [

{

 "to": {

    "id": "11227351"

  },

  "types": \[

    {

      "associationCategory": "HUBSPOT\_DEFINED",

      "associationTypeId": 204

    } ]

},

{

 "to": {

    "id": "6126491292"

  },

  "types": \[

    {

      "associationCategory": "HUBSPOT\_DEFINED",

      "associationTypeId": 191

    } ]

}

]

}

Thanks and I hope someone faced this problem before and is able to help me.

Hey, @MatiasDuro :waving_hand: The Association Type IDs are uni-directional. Meaning, Task > Contact is different from Contact > Task. We can use this end point to get the correct IDs based on the “direction” of the association you are making:

GET /crm/v4/associations/{fromObjectType}/{toObjectType}/labels

For example:

Task > Contact

GET crm/v3/associations/task/contact/types

Returns 204

{
 "results": [
 {
 "id": "204",
 "name": "task_to_contact"
 }
 ]
}

and

Contact to Task

GET crm/v3/associations/contacts/tasks/types

Returns 203

{
 "results": [
 {
 "id": "203",
 "name": "contact_to_task"
 }
 ]
}

Task > Company

GET /crm/v3/associations/task/company/types

Returns 192

{
 "results": [
 {
 "id": "192",
 "name": "task_to_company"
 }
 ]
}

In summary, make sure you are using the type ID for the correction “direction”. Task > Company and Task > Contact and you should be good to go.

Have fun building! — Jaycee