Hello everyone
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
bu with my JS, I can’t achieve it.
Has anyone managed to succeed in this operation?
A thousand thanks for your help
Y.