I've to attach task with my custom object. I'm using below code as defined in docs. But I can't able to create it and my object name is 'test'.
I've created Association class in PHP:
Association::create($from, $to, $type, $fromObjectType, $toObjectType);
$from => task_id
$to => custom_object_id
$type => I've custom object name test so I passed test_to_task
I don't have idea about $fromObjectType, $toObjectType.
Where create method contains below code:
public function create($from, $to, $type, $fromObjectType, $toObjectType)
{
$fromId = new PublicObjectId([
'id' => $from,
]);
$toId = new PublicObjectId([
'id' => $to,
]);
$publicAssociation1 = new PublicAssociation([
'from' => $fromId,
'to' => $toId,
'type' => $type,
]);
$batchInputPublicAssociation = new BatchInputPublicAssociation([
'inputs' => [$publicAssociation1],
]);
return $hubSpot->crm()->associations()->batchApi()->create($fromObjectType, $toObjectType, $batchInputPublicAssociation);
}
Where $hubSpot is:
Factory::createWithAccessToken('access_token');
When making an API call to create an association, the fromObjectType should contain the internal name of the object, so 'contact' or 'company', the same goes for the toObjectType. So in your case, you can use 'task' and 'test' for the two variables.
Learn more about HubSpot by following me on LinkedIn or YouTube
✅ Did my answer solve your issue? Help the community by marking it as the solution.