APIs & Integrations

CHamelin
Member

Unable to find company associated to deal in Workflow Custom Code action

SOLVE

Hello HubSpot team,

I am building a custom automation inside a Workflow Custom Code action to synchronise revenue share values from a partner company record into the company associated to a deal.

My intended flow is:

 

  • Read the partner company name from a field on the deal 

  • Use HubSpot’s Search API to find the partner company record by name

  • Retrieve the company associated to the triggering deal

  • Copy key property values (e.g. revenue share type and amount) from the partner company into the associated company record

 

Originally I tried this by using “Edit Record” → “Associated Company” in the workflow, but the action failed to update the record, even though I could retrieve the values from the partner company data in the workflow.

 

I am now trying to update the associated company directly using HubSpot’s custom code action, using this approach:

 

const associations = await client.crm.associations.v4.basicApi.getPage(
'deal',
triggerId,
'company'
);
const associatedCompanyId = associations.results?.[0]?.id;

 

However, no matter what I try, I always get either:

  • associations.results is empty

  • results[0].id is undefined

Even though I know (and can see in the UI + API Explorer) that the deal is associated to a company.

My portal does have linked labels / custom association labels between deals and companies (like “Partner Company” or “Customer Company”).

 

Could you please advise:

  • What is the officially recommended pattern in 2025 to reliably get the associated company ID from a deal inside a workflow custom code action?

  • Is my intented flow the right to go about it ? 

Thank you so much for your help!

0 Upvotes
1 Accepted solution
evaldas
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Unable to find company associated to deal in Workflow Custom Code action

SOLVE

Hi @CHamelin,

 

Have you tried using getAll() instead of basicApi.getPage() ?

 

If your associations uses custom labels such as "Partner Company" or "Customer Company", then it might be the reason why you are seeing empty results. 

 

Below is an example of how this could look like with using getAll():

 

const TARGET_ASSOCIATION_TYPE_ID = 27;

const associations = await client.crm.associations.v4.getAll('deal', triggerId, 'company');

const filtered = associations.results.find(
  assoc => assoc.associationTypeId === TARGET_ASSOCIATION_TYPE_ID
);

const associatedCompanyId = filtered?.toObjectId;

 

The TARGET_ASSOCIATION_TYPE_ID should match the ID of the association label you are trying to target, which you can retrieve by doing a GET on the /crm/v4/associations/deal/company/labels endpoint.

 

Hope this helps!

 

✔️ Did this post help answer your query? Help the community by marking it as a solution.

View solution in original post

0 Upvotes
1 Reply 1
evaldas
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Unable to find company associated to deal in Workflow Custom Code action

SOLVE

Hi @CHamelin,

 

Have you tried using getAll() instead of basicApi.getPage() ?

 

If your associations uses custom labels such as "Partner Company" or "Customer Company", then it might be the reason why you are seeing empty results. 

 

Below is an example of how this could look like with using getAll():

 

const TARGET_ASSOCIATION_TYPE_ID = 27;

const associations = await client.crm.associations.v4.getAll('deal', triggerId, 'company');

const filtered = associations.results.find(
  assoc => assoc.associationTypeId === TARGET_ASSOCIATION_TYPE_ID
);

const associatedCompanyId = filtered?.toObjectId;

 

The TARGET_ASSOCIATION_TYPE_ID should match the ID of the association label you are trying to target, which you can retrieve by doing a GET on the /crm/v4/associations/deal/company/labels endpoint.

 

Hope this helps!

 

✔️ Did this post help answer your query? Help the community by marking it as a solution.

0 Upvotes