How to associate Task with Custom object?

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');

Hi @KPadhiyar ,

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.

Hi @Teun, Thanks for the answer. I’ve done same thing before posting here. But its gives me error like:

[ 400] Client error: `POST https://api.hubapi.com/crm/v3/associations/task/test/batch/create\` resulted in a ` 400 Bad Request` response:
{“status”:“error”,“message”:“Unable to infer object type from: test”.
I’m using below code:
Association::make($hubSpotAccount)->create(
task_id,
test_object object_id,
“test_to_task”,
“task”,
“test”
);

I’m still finding solution for above.
Thanks!