APIs & Integrations

NelsonS
Contributor | Gold Partner
Contributor | Gold Partner

How can I associate a task to a custom object?

Hello community,

 

I was doing some tests, but I can't manage to associate a contact object task to a custom object.

 

The ID of the contact record: 225551
The ID of the custom object record: 270540578
The ID of the custom object: 2-2316394

 

I run the code, and it does not appear in the chronological activity of the custom object, but it does appear in contact without the association with the custom object.

 

This is the code to create a task:

 

 

 

 

 

import requests
import json

url = "https://api.hubapi.com/engagements/v1/engagements"

querystring = {"hapikey":os.environ["APIKEY"]}
payload = json.dumps({
    "engagement": {
        "active": 'true',
        "ownerId": 79870886,
        "type": "TASK",
    },
    "associations": {
        "contactIds": [225551],
        "companyIds": [ ],
        "dealIds": [ ],
        "ownerIds": [270540578]
    },
    "metadata": {
        "body": "This is the body",
        "subject": "Task title",
        "status": "NOT_STARTED",
        "reminders": [1644840000000],
        "forObjectType": "CONTACT"
    }
});
headers = {
    'Content-Type': "application/json",
    }

response = requests.request("POST", url, data=payload, headers=headers, params=querystring)

print(response.text)

 

 

 

 

 

Another test I performed was :

 

I change the value of the "forObjectType" field to the Id of the custom object and I get the following error.

 

 

 

{"status":"error","message":"Unable to process JSON","correlationId":"fe40b6e1-5f34-4ac5-a629-8aa65ab224a"}

 

 

 

 

Thanks

2 Replies 2
dennisedson
HubSpot Product Team
HubSpot Product Team

How can I associate a task to a custom object?

@NelsonS 

Curious to know if my reply in this thread still holds true...

Thanks,

Dennis




HubSpot Community Developer ShowMake sure to subscribe to our YouTube channel
where you can find the HubSpot Community Developer Show
NelsonS
Contributor | Gold Partner
Contributor | Gold Partner

How can I associate a task to a custom object?

Hi @dennisedson , I was checking the API associations, and it does not support engagements, it can only be associated with native hubspot objects (contact, company, deal, ticket, quotes, line items).

 

associations_engagements.png

Thank you very much anyway

0 Upvotes