# Create Custom Object Association in Custom code in Workflow

**URL:** <https://community.hubspot.com/t/create-custom-object-association-in-custom-code-in-workflow/45838>\
**Category:** APIs & Integrations\
**Tags:** workflows, sdk\
**Created:** [October 22, 2021, 8:08pm UTC](https://community.hubspot.com/t/create-custom-object-association-in-custom-code-in-workflow/45838 "2021-10-22T20:08:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sylg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sylg/32/95715_2.png) [@Sylg](https://community.hubspot.com/u/Sylg)\
**Post date:** [October 22, 2021, 8:08pm UTC](https://community.hubspot.com/t/create-custom-object-association-in-custom-code-in-workflow/45838/1 "2021-10-22T20:08:02Z")

</div>

Hey Everyone,

I’m building a workflow that will

1. find the associated company of a workspace (custom object)
2. look if this company has an associated open deal
3. If so, associate the workspace to the deal

On paper, this is straight forward but I can’t find the function of the nodeJs library to lookup association on a custom object and to create an association on a custom object

According to the [CRM API v3 docs](https://developers.hubspot.com/docs/api/crm/crm-custom-objects), it should be

`hubspotClient.crm.associationsApi.getAll(objectType, objectId, toObjectType, after, limit);`

to lookup an association but this return

`{"errorType":"TypeError","errorMessage":"Cannot read property 'getAll' of undefined","stack":["TypeError: Cannot read property 'getAll' of undefined"," at Object.exports.main`

I tried doing the call via HTTP in Postman and the endpoint work.

Can someone tell me the function to lookup associated objects and the function to create an association with a custom object, please?

Thanks

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [October 25, 2021, 3:56pm UTC](https://community.hubspot.com/t/create-custom-object-association-in-custom-code-in-workflow/45838/2 "2021-10-25T15:56:28Z")

</div>

@kierana maybe you have some ideas 😀

---

<div class="post-metadata">

**Author:** ![kierana](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kierana/32/44503_2.png) [@kierana](https://community.hubspot.com/u/kierana)\
**Post date:** [October 25, 2021, 4:03pm UTC](https://community.hubspot.com/t/create-custom-object-association-in-custom-code-in-workflow/45838/3 "2021-10-25T16:03:38Z")

</div>

The documentation is actually incorrect for this - It’s always worth using Intellisense in your IDE to get the right methods. Try

`hubspotClient.crm.objects.associationsApi.getAll(.....)`

---

<div class="post-metadata">

**Author:** ![NMueller](https://avatars.discourse-cdn.com/v4/letter/n/ac8455/32.png) [@NMueller](https://community.hubspot.com/u/NMueller)\
**Post date:** [May 26, 2022, 6:26pm UTC](https://community.hubspot.com/t/create-custom-object-association-in-custom-code-in-workflow/45838/4 "2022-05-26T18:26:59Z")

</div>

Hello, I am in a similar situation as @Sylg. And this solution is not working for me.  
I am creating a workflow with custom code actions that needs to look up associations for one custom object to another custom object.  
So I have tested and confirmed this endpoint is working from the docs:

 ![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/5/5/5588a1fb1ddd4dd0432ee7fe7c506c1d0a03c556.png)

And brought the relevant code into the custom code action in my workflow. But I ran into same error as mentioned above.

`{"errorType":"TypeError","errorMessage":"Cannot read property 'getAll' of undefined","stack":[ ...`

And then I found this thread! So I have updated my script within the custom code action to include hubspotClient.crm. **objects**.associationsApi.getAll(…), as seen below.

 ![Screen Shot 2022-05-26 at 1.22.35 PM.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/b/be27ab90f8f02493326681f57c1991425ce9f78e.png)

And now I am running into this:

```lia-code-sample
ERROR	{
 "statusCode": 500,
 "body": {
 "status": "error",
 "message": "internal error",
 "correlationId": "164444ce-8a12-4bd6-bf03-9538ee174fd9"
 } ...

```

At this point, I’m kinda lost! Anybody know how to list associations from custom object to custom object correctly?

---

<div class="post-metadata">

**Author:** ![NMueller](https://avatars.discourse-cdn.com/v4/letter/n/ac8455/32.png) [@NMueller](https://community.hubspot.com/u/NMueller)\
**Post date:** [May 26, 2022, 6:50pm UTC](https://community.hubspot.com/t/create-custom-object-association-in-custom-code-in-workflow/45838/5 "2022-05-26T18:50:20Z")

</div>

Gah! Just discovered, I need to utilize V4 API documentation as seen here [Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/api/crm/associations) to get this working. I’ve updated my custom code in workflow, and it is working now with V4 formatted request:

 ![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/1/9/1962bdaedadd5a3dd30d87b1550b2a0dd800fc04.png)

---

<div class="post-metadata">

**Author:** ![DStaat](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dstaat/32/3537_2.png) [@DStaat](https://community.hubspot.com/u/DStaat)\
**Post date:** [August 29, 2023, 7:58pm UTC](https://community.hubspot.com/t/create-custom-object-association-in-custom-code-in-workflow/45838/6 "2023-08-29T19:58:16Z")

</div>

Hey @Sylg,  
I know this thread is a bit old but have you heard of Associ8? It associates objects (Custom Objects included) via workflow based off criteria you set!

 ![DStaat_0-1693339004798.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/7/b/7b928cad73ea09e659f75648418bdaba3cfb0dd0.png)

You can check it out on the HubSpot Marketplace [here](https://ecosystem.hubspot.com/marketplace/apps/productivity/workflow-automation/associations-app-272901).  
If you have any questions, feel free to reach out to me!  
Best,  
-David Staat
