# Get Associations from Custom Object

**URL:** <https://community.hubspot.com/t/get-associations-from-custom-object/89345>\
**Category:** APIs & Integrations\
**Created:** [September 11, 2023, 11:28am UTC](https://community.hubspot.com/t/get-associations-from-custom-object/89345 "2023-09-11T11:28:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![YoussefEA](https://avatars.discourse-cdn.com/v4/letter/y/59ef9b/32.png) [@YoussefEA](https://community.hubspot.com/u/YoussefEA)\
**Post date:** [September 11, 2023, 11:28am UTC](https://community.hubspot.com/t/get-associations-from-custom-object/89345/1 "2023-09-11T11:28:56Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [September 12, 2023, 8:43pm UTC](https://community.hubspot.com/t/get-associations-from-custom-object/89345/2 "2023-09-12T20:43:51Z")

</div>

Hi, there. I have two questions.

- You mention custom objects, but your code example looks to be a request for associations for the Contact Object. Is that correct?
- The code you posted appears to have duplicated code in it. Is that intentional?

Additional steps:

- If you are working with specific Custom Object records, can you try making a test from the documentation page, please? For a single record with associations.
- If that works, our next step is to have you do it in Postman.
- Please share your request and response here.

I hope by getting the request straightened out, you’ll be able to take it from there with your custom code.

Thanks for the additional information! — Jaycee
