batch association PHP API

Hello, I’m trying to get all associations between contacts and companies by using a single call (right now I’m using several API calls, one for each contact).

This is the code I’ve tried:

$hs_client->crm()->associations()->BatchApi()->read('contacts', 'companies', null)

But I’m getting an exception:

{"status":"error","message":"Invalid JSON input: a request body was expected, but none found","correlationId":"fc8d408f-17fb-4fe2-b4b4-6d05588e2f4f","category":"VALIDATION_ERROR"}

Can anyone help?

Thank you!

Hey @GPanisi, It looks like you need to pass in the list of contact and company IDs you want to get the associations for.

You can pass in an array of objects, where each object contains the IDs you want to get the associations for.
<code>[
{
“contacted”: “123”,contacted
“companyId”: “456”
},
{
“contactId”: “789”,
contacted “companyId”: “012”
}
]
</code>