Get associations with getbyID from a Custom Object

Hello everyone :slightly_smiling_face:

I’m not sure if I’m doing this right. I’ve found some inefficient information on how to call the associations of a Custom Object.

Here’s what I’ve attempted to do:

javascript

const apiResponse = await hubspotClient.crm.objects.basicApi.getById('p1234567_contracts', contractId,["company","associations"]); console.log(apiResponse); if (apiResponse.associations && apiResponse.associations.companies && apiResponse.associations.companies.results.length > 0) { const companyId = apiResponse.associations.companies.results[0].id; console.log('company ID :', companyId); updateProperties.properties.hs_associated_company_id = companyId; } } catch (error) { console.error('Error Not Found', error); } const apiResponse = await hubspotClient.crm.objects.basicApi.getById('p1234567_contracts', contractId,["company","associations"]); console.log(apiResponse); if (apiResponse.associations && apiResponse.associations.companies && apiResponse.associations.companies.results.length > 0) { const companyId = apiResponse.associations.companies.results[0].id; console.log('company ID :', companyId); updateProperties.properties.hs_associated_company_id = companyId; } } catch (error) { console.error('Error Not Found', error); }

If the associations are returned correctly with a simple request: https://api.hubapi.com/crm/v3/objects/contracts/123467899?properties=contracts&&associations=company

With my JS, I can’t achieve it.

Has anyone managed to succeed in this operation?

A thousand thanks for your help :slightly_smiling_face:

Hey, @YoussefEA :waving_hand: Were you able to make any progress? If so, can you share what worked? If not, we can try tagging a few community members to share how they’d make a similar request.

Best,

Jaycee