<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Associate Deal to Company in Data Hub</title>
    <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/985257#M2355</link>
    <description>&lt;P&gt;Share your code and errors if you need help&lt;/P&gt;</description>
    <pubDate>Fri, 31 May 2024 14:41:53 GMT</pubDate>
    <dc:creator>louischausse</dc:creator>
    <dc:date>2024-05-31T14:41:53Z</dc:date>
    <item>
      <title>Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/818219#M1626</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on using HubSpot Custom Code Workflow Actions to associate the deal in the workflow with a specific company (I already know the company ID).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the property included in the code, I have the Deal ID as&amp;nbsp;hs_object_id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I have written:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;const hubspot = require('@hubspot/api-client')&lt;/P&gt;&lt;P&gt;exports.main = (event, callback) =&amp;gt; {&lt;BR /&gt;const hubspotClient = new hubspot.Client({&lt;BR /&gt;accessToken: process.env.redacted&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;async function associateDealWithCompany(dealId, companyId) {&lt;BR /&gt;try {&lt;BR /&gt;const association = {&lt;BR /&gt;"inputs": [&lt;BR /&gt;{&lt;BR /&gt;"from": {&lt;BR /&gt;"id": event.inputFields['hs_object_id']&lt;BR /&gt;},&lt;BR /&gt;"to": {&lt;BR /&gt;"id": 16319160389&lt;BR /&gt;},&lt;BR /&gt;"type": "deal_to_company"&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;};&lt;BR /&gt;await hubspotClient.crm.associations.batchApi.create('deals', 'companies', association);&lt;BR /&gt;console.log(`Deal ${dealId} has been associated with company ${companyId}`);&lt;BR /&gt;} catch (err) {&lt;BR /&gt;console.error(err);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The&amp;nbsp;&lt;SPAN&gt;hs_execution_state status response is success.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please help me - thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 14:13:52 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/818219#M1626</guid>
      <dc:creator>iingallslawtige</dc:creator>
      <dc:date>2023-07-11T14:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/818654#M1627</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/550279"&gt;@iingallslawtige&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;Thanks for reaching out to the Community!&lt;BR /&gt;&lt;BR /&gt;I found on this similar post "&lt;A href="https://community.hubspot.com/t5/APIs-Integrations/Creating-An-Association-In-Custom-Code-Workflow/m-p/701287" target="_blank" rel="noopener"&gt;Creating An Association In Custom Code Workflow&lt;/A&gt;" several options that might work for you.&lt;BR /&gt;&lt;BR /&gt;I also wanted to invite a couple of subject matter experts to this conversation&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/20261"&gt;@louischausse&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101258"&gt;@Teun&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/313109"&gt;@HFisher7&lt;/a&gt;: do you have any tips to help&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/550279"&gt;@iingallslawtige&lt;/a&gt;&amp;nbsp;to associate a deal to a specific company via a custom coded workflow action please?&lt;BR /&gt;&lt;BR /&gt;Thanks and have a lovely day!&lt;BR /&gt;Bérangère&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 08:25:06 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/818654#M1627</guid>
      <dc:creator>BérangèreL</dc:creator>
      <dc:date>2023-07-12T08:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/818810#M1628</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/550279"&gt;@iingallslawtige&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Do you have an error in the console? If yes please copy/paste it here.&lt;BR /&gt;Do you want to apply an association label or not?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 13:21:50 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/818810#M1628</guid>
      <dc:creator>louischausse</dc:creator>
      <dc:date>2023-07-12T13:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/818862#M1629</link>
      <description>&lt;P&gt;Hi Louis, thanks for the message!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on &lt;A href="https://github.com/HubSpot/hubspot-api-nodejs/blob/master/codegen/crm/objects/apis/AssociationsApi.ts#L101" target="_blank" rel="noopener"&gt;Version 8.9&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Not looking for an association label (unless required). Just looking to associate the deal with a company.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Current Code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;const hubspot = require('@hubspot/api-client');

exports.main = (event, callback) =&amp;gt; {
  const hubspotClient = new hubspot.Client({
    accessToken: process.env.secret
  });
 hubspotClient.crm.objects.associationsApi.create("DEAL",event.inputFields['hs_object_id'],"COMPANY",16319160389,"deal_to_company",5)
.catch(err =&amp;gt; {
    console.error(err);
});
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Error Message:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;2023-07-12T14:11:54.028Z	ERROR	TypeError: Cannot read properties of undefined (reading 'makeRequestContext')
    at AssociationsApiRequestFactory.&amp;lt;anonymous&amp;gt; (/opt/nodejs/node_modules/@hubspot/api-client/lib/codegen/crm/objects/apis/AssociationsApi.js:87:55)
    at Generator.next (&amp;lt;anonymous&amp;gt;)
    at /opt/nodejs/node_modules/@hubspot/api-client/lib/codegen/crm/objects/apis/AssociationsApi.js:8:71
    at new Promise (&amp;lt;anonymous&amp;gt;)
    at __awaiter (/opt/nodejs/node_modules/@hubspot/api-client/lib/codegen/crm/objects/apis/AssociationsApi.js:4:12)
    at AssociationsApiRequestFactory.create (/opt/nodejs/node_modules/@hubspot/api-client/lib/codegen/crm/objects/apis/AssociationsApi.js:64:16)
    at ObservableAssociationsApi.create (/opt/nodejs/node_modules/@hubspot/api-client/lib/codegen/crm/objects/types/ObservableAPI.js:29:59)
    at PromiseAssociationsApi.create (/opt/nodejs/node_modules/@hubspot/api-client/lib/codegen/crm/objects/types/PromiseAPI.js:14:33)
    at Object.exports.main (/var/task/file.js:7:44)
    at Runtime.exports.hubspot_handler [as handler] (/var/task/hubspotHandler.js:6:21)

Memory: 72/128 MB
Runtime: 854.28 ms&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 14:59:52 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/818862#M1629</guid>
      <dc:creator>iingallslawtige</dc:creator>
      <dc:date>2023-07-12T14:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/819040#M1630</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/550279"&gt;@iingallslawtige&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I saw some inconsistencies lately using hubspot node js client with the association API.&lt;BR /&gt;&lt;BR /&gt;I prefer to use axios.&lt;BR /&gt;&lt;BR /&gt;Here's how it goes:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const axios = require('axios');

exports.main = async (event) =&amp;gt; {
 
  const dealId = event.inputFields['hs_object_id'];
  const token = process.env.secret
  const companyId = "16319160389" 

  // define associate() function

  async function associate(fromObjectType,fromObjectId,toObjectType,toObjectId) {

    console.log(`trying to associate ${fromObjectType} of id ${fromObjectId} with ${toObjectType} of id ${toObjectId}...`)

    const options = {
      method: 'PUT',
      url: `https://api.hubapi.com/crm/v4/objects/${fromObjectType}/${fromObjectId}/associations/default/${toObjectType}/${toObjectId}`,
      headers: {
        'content-type': 'application/json',
        'accept': 'application/json',
        'authorization': `Bearer ${token}`
      }
    };

    try {
      const response = await axios(options);
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  //exexute associate() function
      var fromObjectType = "deals"
      var fromObjectId = dealId
      var toObjectType = companies
      var toObjectId = companyId
      associate(fromObjectType,fromObjectId,toObjectType,toObjectId)
        .then(association =&amp;gt; {
        console.log(association.status);
        console.log(association.results[0]);
      })
        .catch(error =&amp;gt; {
        console.error(error);
      });
}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 12 Jul 2023 18:38:28 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/819040#M1630</guid>
      <dc:creator>louischausse</dc:creator>
      <dc:date>2023-07-12T18:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/819050#M1631</link>
      <description>&lt;P&gt;Amazing, that worked perfectly. Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 18:57:55 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/819050#M1631</guid>
      <dc:creator>iingallslawtige</dc:creator>
      <dc:date>2023-07-12T18:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/821658#M1648</link>
      <description>&lt;P&gt;Hey iingallslawtige,&lt;BR /&gt;&lt;BR /&gt;We have an app called Associ8 that would solve your problem. No code required! It creates a workflow action that associates objects together based on your search parameters (the company ID and deal ID in your case). Check it out &lt;A href="https://ecosystem.hubspot.com/marketplace/apps/productivity/workflow-automation/associations-app-272901" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;Let me know if you have any questions or need help setting up. I'd be happy to hop on a call with you!&lt;BR /&gt;&lt;BR /&gt;Best,&lt;BR /&gt;&lt;BR /&gt;-David Staat&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2023 19:43:19 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/821658#M1648</guid>
      <dc:creator>DStaat</dc:creator>
      <dc:date>2023-07-18T19:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/979175#M2324</link>
      <description>&lt;P&gt;I'm looking to get code to work to associate deals we're creating via API/Web forms to the correct companys (company IDs will be known as a deal property value). I've looked at multiple other community posts but non of the codes are quite right and erroring when trying to run them. any help would be appreciated!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 16:24:03 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/979175#M2324</guid>
      <dc:creator>CraigObee</dc:creator>
      <dc:date>2024-05-20T16:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/983783#M2351</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/336201"&gt;@CraigObee&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;CAn you share your existing core and the error you get?&lt;BR /&gt;&lt;BR /&gt;Also can you share where the code is hosted? Is it in your app or in a custom coded action in a HubSpot workflow?&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2024 12:28:13 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/983783#M2351</guid>
      <dc:creator>louischausse</dc:creator>
      <dc:date>2024-05-29T12:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/983819#M2352</link>
      <description>&lt;P&gt;Hi Louis, my colleague managed to get it working. it was using custom code on a deal workflow where the company ID value was present in a deal property.&lt;/P&gt;&lt;P&gt;We're now working on doing this for tickets. applying this to deal and ticket workflows will address an annoying issue we have which I raised in a separate post.&amp;nbsp;&lt;A href="https://community.hubspot.com/t5/HubSpot-Ideas/Associate-only-companies-associated-to-the-existing-Deal-when/idi-p/885137" target="_blank"&gt;https://community.hubspot.com/t5/HubSpot-Ideas/Associate-only-companies-associated-to-the-existing-Deal-when/idi-p/885137&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2024 13:13:15 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/983819#M2352</guid>
      <dc:creator>CraigObee</dc:creator>
      <dc:date>2024-05-29T13:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/985257#M2355</link>
      <description>&lt;P&gt;Share your code and errors if you need help&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 14:41:53 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/985257#M2355</guid>
      <dc:creator>louischausse</dc:creator>
      <dc:date>2024-05-31T14:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/1080873#M2752</link>
      <description>&lt;P&gt;Hi Louis,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologies, I'm not a developer and I can't really understand. Are you able to create a code (whether in Python or Node.jx as these are the only ones avaiable in Custom Code) to associate a deal with the primary company the contact is from. I've looked around for different codes and tried and none of them worked.&lt;BR /&gt;&lt;BR /&gt;Would be great thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;M&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 13:13:26 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/1080873#M2752</guid>
      <dc:creator>MSaurat</dc:creator>
      <dc:date>2024-12-09T13:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/1080880#M2753</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/569875"&gt;@MSaurat&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Have you tried the no code solutions to associate record in workflows? It's new in beta and may fit your need:&amp;nbsp;&lt;A href="https://knowledge.hubspot.com/workflows/manage-crm-record-associations-with-workflows" target="_blank"&gt;https://knowledge.hubspot.com/workflows/manage-crm-record-associations-with-workflows&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;To activate the beta you need to click on Avatar (top right corner) &amp;gt; Product updates and search for "New Workflow Actions for Associations"&lt;BR /&gt;&lt;BR /&gt;If it doesn't work for your use case, contact me through this form (&lt;A href="https://www.auxilio.io/en/contact" target="_blank"&gt;https://www.auxilio.io/en/contact&lt;/A&gt;) and I'll send you a quote to develop a custom automation for you.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 13:25:01 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/1080880#M2753</guid>
      <dc:creator>louischausse</dc:creator>
      <dc:date>2024-12-09T13:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/1080921#M2755</link>
      <description>&lt;P&gt;Hey Louis,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes I've tried and tested but nothing in the way of associating a deal wirh a contact primary company. If you have some tips let me know.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 14:30:07 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/1080921#M2755</guid>
      <dc:creator>MSaurat</dc:creator>
      <dc:date>2024-12-09T14:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Associate Deal to Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/1080931#M2756</link>
      <description>&lt;P&gt;It depends of your process. What is the trigger? When the deal hits a specific stage?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 14:35:06 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-Deal-to-Company/m-p/1080931#M2756</guid>
      <dc:creator>louischausse</dc:creator>
      <dc:date>2024-12-09T14:35:06Z</dc:date>
    </item>
  </channel>
</rss>

