<?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: Custom code to assign Primary Company in Data Hub</title>
    <link>https://community.hubspot.com/t5/Data-Hub/Custom-code-to-assign-Primary-Company/m-p/1158150#M3081</link>
    <description>&lt;P&gt;Hey, &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/761251"&gt;@HZaremba&lt;/a&gt;&lt;/SPAN&gt; &lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; thank for your question. To confirm, you are doing this via a custom coded workflow action, correct? Have you tried breaking these calls up and testing in Postman? — Jaycee&lt;/P&gt;</description>
    <pubDate>Wed, 28 May 2025 21:56:13 GMT</pubDate>
    <dc:creator>Jaycee_Lewis</dc:creator>
    <dc:date>2025-05-28T21:56:13Z</dc:date>
    <item>
      <title>Custom code to assign Primary Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Custom-code-to-assign-Primary-Company/m-p/1157948#M3080</link>
      <description>&lt;P&gt;Hi, I need to assign a new company as a primary one. I do this in the automation, via a custom code. At first I start with removing the existing association and later set a new primary company. Everything looks fine in a log, but give no result - the new company is still no a Primary one. It would be great to understand what can be the issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have those two steps&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;await hubspotClient.apiRequest({&lt;BR /&gt;method: 'POST',&lt;BR /&gt;path: '/crm/v4/associations/contacts/companies/batch/archive',&lt;BR /&gt;body: companies.map(c =&amp;gt; ({&lt;BR /&gt;from: { id: contactId },&lt;BR /&gt;to: [{ id: c.toObjectId }]&lt;BR /&gt;}))&lt;BR /&gt;});&lt;BR /&gt;await hubspotClient.apiRequest({&lt;BR /&gt;method: 'PUT',&lt;BR /&gt;path: `/crm/v4/objects/contact/${contactId}/associations/company/${bestCompanyId}`,&lt;BR /&gt;body: [&lt;BR /&gt;{ associationCategory: 'HUBSPOT_DEFINED', associationTypeId: 279 }, // default&lt;BR /&gt;{ associationCategory: 'HUBSPOT_DEFINED', associationTypeId: 1 } // primary&lt;BR /&gt;]&lt;BR /&gt;});&lt;BR /&gt;&lt;BR /&gt;Could you suggest what can be wrong?&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 12:20:40 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Custom-code-to-assign-Primary-Company/m-p/1157948#M3080</guid>
      <dc:creator>HZaremba</dc:creator>
      <dc:date>2025-05-28T12:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Custom code to assign Primary Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Custom-code-to-assign-Primary-Company/m-p/1158150#M3081</link>
      <description>&lt;P&gt;Hey, &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/761251"&gt;@HZaremba&lt;/a&gt;&lt;/SPAN&gt; &lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; thank for your question. To confirm, you are doing this via a custom coded workflow action, correct? Have you tried breaking these calls up and testing in Postman? — Jaycee&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 21:56:13 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Custom-code-to-assign-Primary-Company/m-p/1158150#M3081</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2025-05-28T21:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: Custom code to assign Primary Company</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Custom-code-to-assign-Primary-Company/m-p/1158151#M3082</link>
      <description>&lt;P&gt;Test 1:&lt;/P&gt;
&lt;P&gt;Check current associations&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;GET https://api.hubapi.com/crm/v4/objects/contact/{contactId}/associations/company&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test 2:&lt;/P&gt;
&lt;P&gt;Test the Archive call&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;POST https://api.hubapi.com/crm/v4/associations/contacts/companies/batch/archive&lt;/LI-CODE&gt;&lt;LI-CODE lang="javascript"&gt;[{
  "from": { "id": "your-contact-id" },
  "to": { "id": "company-id-to-remove" },
  "associationTypes": [
    { "associationCategory": "HUBSPOT_DEFINED", "associationTypeId": 279 }
  ]
}]&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test 3:&lt;/P&gt;
&lt;P&gt;Test the Primary Association&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;PUT https://api.hubapi.com/crm/v4/objects/contact/{contactId}/associations/company/{bestCompanyId}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm sure there are other ways to test this, but it's how I would start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Jaycee&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 22:02:22 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Custom-code-to-assign-Primary-Company/m-p/1158151#M3082</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2025-05-28T22:02:22Z</dc:date>
    </item>
  </channel>
</rss>

