<?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: Get all deals from a company and associate them (deals) to a contact in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Get-all-deals-from-a-company-and-associate-them-deals-to-a/m-p/784554#M63325</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all you need to use the&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;/crm/v3/objects/companies/{companyId}&lt;/EM&gt; endpoint, where you provide the &lt;EM&gt;companyId&lt;/EM&gt; and provide the &lt;EM&gt;deal&lt;/EM&gt; as value for the &lt;EM&gt;associations&lt;/EM&gt; param, like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const companyId = "123456789";
const properties = [];
const propertiesWithHistory = undefined;
const associations = ["deal"];
const archived = false;
const idProperty = undefined;

const apiResponse = await hubspotClient.crm.companies.basicApi.getById(companyId, properties, propertiesWithHistory, associations, archived, idProperty);&lt;/LI-CODE&gt;&lt;P&gt;Response:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "id": "123456789",
  "properties": {
    "createdate": "...",
    "domain": "xyz.com",
    "hs_lastmodifieddate": "...",
    "hs_object_id": "123456789",
    "name": "xzy"
  },
  "createdAt": "...",
  "updatedAt": "...",
  "archived": false,
  "associations": {
    "deals": {
      "results": [
        {
          "id": "987654321",
          "type": "company_to_deal"
        }
      ]
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;Now you have all the deal ids connected to the company.&lt;/P&gt;&lt;P&gt;After this, you will add these deal ids to the request when you create the contact via&amp;nbsp;&lt;EM&gt;/crm/v3/objects/contacts:&lt;/EM&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const properties = {
  "company": "Biglytics",
  "email": "bcooper@biglytics.net",
  "firstname": "Bryan",
  "lastname": "Cooper",
  "phone": "(877) 929-0687",
  "website": "biglytics.net"
};
const SimplePublicObjectInputForCreate = { properties, associations: [
  {
     "to":{"id":"987654321"},
     "types":[{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":4}]
  },
  {
     "to":{"id":"999999999"},
     "types":[{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":4}]
  },
]};

const apiResponse = await hubspotClient.crm.contacts.basicApi.create(SimplePublicObjectInputForCreate);&lt;/LI-CODE&gt;&lt;P&gt;You find some documentation &lt;A href="https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview" target="_blank"&gt;here&lt;/A&gt; why the associationTypeId is equal to 4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;Hunor&lt;/P&gt;</description>
    <pubDate>Thu, 20 Apr 2023 17:02:48 GMT</pubDate>
    <dc:creator>HunorSZ</dc:creator>
    <dc:date>2023-04-20T17:02:48Z</dc:date>
    <item>
      <title>Get all deals from a company and associate them (deals) to a contact</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Get-all-deals-from-a-company-and-associate-them-deals-to-a/m-p/784477#M63319</link>
      <description>&lt;P&gt;&amp;nbsp;Hello. I am still very new to HubSpot/HubL development and I am struggling to achieve something that I believe should be quite easy (I just can't find it in the docs).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;What I need is to get all Deals from a Company so that I can then Associate these Deals to a/some Contact(s).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I'm using HubSpot Client V8 and Node.js 16.x.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Company-based WorkFlow (Custom Code).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Done so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;1. Check if there is a value for 4 properties (emails) and for each:&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1.1 If there's no email value, do nothing.&lt;/P&gt;&lt;P&gt;&amp;nbsp; 1.2 If there's an email value, check if exists a Contact with that email&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;1.2.1 If there is a Contact, do nothing&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;1.2.2 If not, (a) create a Contact with that email and (b) associate this Contact to the Company&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I need:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Given the company Id ('hs_object_id'), get all the Deals associated with it and associate all these Deals to each of the Contacts that were just created.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This is basically the last thing I do, currently:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const createContact = await hubspotClient.crm.contacts.basicApi.create(SimplePublicObjectInputForCreate);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This is inside my try/catch. Of course, the code is doing a few other things, but the explanation would become way too long.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;For now, I just want to get the Deals and associated with the "createContact" line above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I believe the Deals could be provided while creating the Contact?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const SimplePublicObjectInputForCreate = { 
 properties, 
 associations: 
  [
   // HERE
  ] };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I hope this made sense.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 14:10:26 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Get-all-deals-from-a-company-and-associate-them-deals-to-a/m-p/784477#M63319</guid>
      <dc:creator>FMontenegro</dc:creator>
      <dc:date>2023-04-20T14:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: Get all deals from a company and associate them (deals) to a contact</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Get-all-deals-from-a-company-and-associate-them-deals-to-a/m-p/784554#M63325</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all you need to use the&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;/crm/v3/objects/companies/{companyId}&lt;/EM&gt; endpoint, where you provide the &lt;EM&gt;companyId&lt;/EM&gt; and provide the &lt;EM&gt;deal&lt;/EM&gt; as value for the &lt;EM&gt;associations&lt;/EM&gt; param, like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const companyId = "123456789";
const properties = [];
const propertiesWithHistory = undefined;
const associations = ["deal"];
const archived = false;
const idProperty = undefined;

const apiResponse = await hubspotClient.crm.companies.basicApi.getById(companyId, properties, propertiesWithHistory, associations, archived, idProperty);&lt;/LI-CODE&gt;&lt;P&gt;Response:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "id": "123456789",
  "properties": {
    "createdate": "...",
    "domain": "xyz.com",
    "hs_lastmodifieddate": "...",
    "hs_object_id": "123456789",
    "name": "xzy"
  },
  "createdAt": "...",
  "updatedAt": "...",
  "archived": false,
  "associations": {
    "deals": {
      "results": [
        {
          "id": "987654321",
          "type": "company_to_deal"
        }
      ]
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;Now you have all the deal ids connected to the company.&lt;/P&gt;&lt;P&gt;After this, you will add these deal ids to the request when you create the contact via&amp;nbsp;&lt;EM&gt;/crm/v3/objects/contacts:&lt;/EM&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const properties = {
  "company": "Biglytics",
  "email": "bcooper@biglytics.net",
  "firstname": "Bryan",
  "lastname": "Cooper",
  "phone": "(877) 929-0687",
  "website": "biglytics.net"
};
const SimplePublicObjectInputForCreate = { properties, associations: [
  {
     "to":{"id":"987654321"},
     "types":[{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":4}]
  },
  {
     "to":{"id":"999999999"},
     "types":[{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":4}]
  },
]};

const apiResponse = await hubspotClient.crm.contacts.basicApi.create(SimplePublicObjectInputForCreate);&lt;/LI-CODE&gt;&lt;P&gt;You find some documentation &lt;A href="https://legacydocs.hubspot.com/docs/methods/crm-associations/crm-associations-overview" target="_blank"&gt;here&lt;/A&gt; why the associationTypeId is equal to 4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;Hunor&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 17:02:48 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Get-all-deals-from-a-company-and-associate-them-deals-to-a/m-p/784554#M63325</guid>
      <dc:creator>HunorSZ</dc:creator>
      <dc:date>2023-04-20T17:02:48Z</dc:date>
    </item>
  </channel>
</rss>

