How to create a Task with a specific company association

Hi,

I’m trying to integrate some functionalities into my application with the use of HubSpot API. Is it possible for me to retrieve a company ID based on company name via a search. The end goal is to create a Task for that specific company. Please advise if a select query can be used to retrieve a company ID.

Hi @CWishiya,

You can retrieve a company based on the company name using this search the CRM API.

Use that endpoint : “/crm/v3/objects/companies/search”

And the body of your request would look like this :

{
 "filterGroups":[
 {
 "filters":[
 {
 "propertyName": "name",
 "operator": "EQ",
 "value": "INSERT THE RELEVANT COMPANY NAME HERE"
 }
 ]
 }
 ]
 }

You can vary the operators if you want to find the company using only part of the name.

Be careful though, if you have a unique identification number for the company, it will smooth the process out as company names can vary from one source to another and it’s harder to match a complex string than a unique id.

You process would look like this :

- create a task (using the tasks API)

- make a search for the company (using the search the CRM API)

- associate the task with the company (using the association v4 API)

Hope this helps !
If it does, please consider marking this answer as a solution :slightly_smiling_face:

Best,

Ludwig

Hey Ludwig,

I have been trying to associate a company with a task, and following v4 api specs, it keeps giving me internal error:

curl -X PUT \
https://api.hubapi.com/crm/v4/objects/task/[TASK_ID]/associations/company/[COMPANY_ID]\
-H 'authorization: Bearer [BEARER_TOKEN]'

{"status":"error","message":"internal error","correlationId":"166164a3-574e-4f4c-ad6e-e3e75139de8e"}

I have redacted actual values of task id, company id, and bearer token, but it does not work.

I have tried swapping to and from object types and ids, same issue. I have tried using ticket instead of task same issue.

I would be great if there is an working example somewhere or someone could tell me what’s wrong here.

Thanks,

Nishant

Never mind, I think I figured it out by reverse looking up the user interface request. I wouldn’t have known where to get this `192` from

So, I was missing this:

--data '[
 {
 "associationCategory": "HUBSPOT_DEFINED",
 "associationTypeId": 192 // <-- I don't know where to get this value from in the doc
 }
]'

Thanks Ludwig, This was really helpful.