Getting associated Contacts of a Company with javascript SDK

I’m using the JavaScript SDK (npm @hubspot/api-client 7.1.2).
I was trying to get all the associated Contacts of a Company like this:

await client.crm.companies.associationsApi.getAll(companyId, 'contact');

However, the result is only non-empty if the company is primary to the contact. Otherwise, the result is empty.
Is it possible to make this work even when the company is non-primary?

Hi, @EHo :waving_hand: Thanks for reaching out. Hey @PCarlson @RMones @kierana @nikodev, do you have any experience here? Thank you! — Jaycee

Hey @EHo ,
I think you may end up having to take a slightly different approach to get this going. I think the client by default utilizes the V3 Association API, which won’t work, as you’ve discovered, when association labels are involved.
I recommend using the V4 Associations API instead:
Here is a sample request:

let options = {
 "method": "GET",
 "path": `/crm/v4/objects/COMPANY/${companyId}/associations/CONTACT?limit=500`,
 "headers": {
 "accept": "application/json",
 "authorization": "Bearer YOUR_ACCESS_TOKEN"
 }
}; 
let companyAssociations = await hubspotClient.apiRequest(options);

console.log(companyAssociations.body)

That should return all associated Contact IDs, regardless of the label, along with the ID of the specific association label.
Good luck!