<?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: Error when using custom code workflow action to merge contacts based on matching phone number in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/856863#M36065</link>
    <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/1377"&gt;@MatthewShepherd&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":raising_hands:"&gt;🙌&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2023 16:12:58 GMT</pubDate>
    <dc:creator>Jaycee_Lewis</dc:creator>
    <dc:date>2023-09-28T16:12:58Z</dc:date>
    <item>
      <title>Error when using custom code workflow action to merge contacts based on matching phone number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/844665#M35757</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We are using a custom code workflow action to attempt to merge contacts if they have a matching Phone Number (phone) contact property.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adapted the code from this example:&amp;nbsp;&lt;A href="https://github.com/HubSpot/sample-workflow-custom-code/blob/main/samples/dedupe_contact.js" target="_blank"&gt;https://github.com/HubSpot/sample-workflow-custom-code/blob/main/samples/dedupe_contact.js&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a&amp;nbsp;&lt;SPAN&gt;Private App set up as a secret, the Private App has the correct scope.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I'm getting this error:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;TypeError: Cannot read properties of undefined (reading 'properties').&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue it is talking about is on line 21 of that github code sample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas what I've set up incorrectly?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 01:58:21 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/844665#M35757</guid>
      <dc:creator>tcxen</dc:creator>
      <dc:date>2023-09-05T01:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using custom code workflow action to merge contacts based on matching phone number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/845709#M35766</link>
      <description>&lt;P&gt;Hey,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/75797"&gt;@tcxen&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; Thanks for your question! Did you get this worked out?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you share your code example here, please? Minus your Private App details &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code block tool can help with formatting as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Seeing how your code looks, helps our community members to give targeted advice. (You didn't do anything wrong, I want to increase our surface area for getting an answer for you if possible)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks! — Jaycee&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 16:16:41 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/845709#M35766</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2023-09-06T16:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using custom code workflow action to merge contacts based on matching phone number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/847330#M35795</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074"&gt;@Jaycee_Lewis&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's my code:&lt;/P&gt;
&lt;PRE&gt;&lt;BR /&gt;/**&lt;BR /&gt;* Searches for another contact with the same value of DEDUPE_PROPERTY.&lt;BR /&gt;* - If no matches are found, nothing happens&lt;BR /&gt;* - If one match is found, the enrolled contact is merged into the matching contact&lt;BR /&gt;* - If more than one match is found, the action fails&lt;BR /&gt;*/&lt;BR /&gt;&lt;BR /&gt;const DEDUPE_PROPERTY = 'phone';&lt;BR /&gt;&lt;BR /&gt;const hubspot = require('@hubspot/api-client');&lt;BR /&gt;&lt;BR /&gt;exports.main = (event, callback) =&amp;gt; {&lt;BR /&gt;// Make sure to add your API key under "Secrets" above.&lt;BR /&gt;const hubspotClient = new hubspot.Client({&lt;BR /&gt;accessToken: process.env.DedupePrivateApp&lt;BR /&gt;});&lt;BR /&gt;&lt;BR /&gt;hubspotClient.crm.contacts.basicApi&lt;BR /&gt;.getById(event.object.objectId, [DEDUPE_PROPERTY])&lt;BR /&gt;.then(contactResult =&amp;gt; {&lt;BR /&gt;let dedupePropValue = contactResult.body.properties[DEDUPE_PROPERTY];&lt;BR /&gt;&lt;BR /&gt;console.log(`Looking for duplicates based on ${DEDUPE_PROPERTY} = ${dedupePropValue}`);&lt;BR /&gt;hubspotClient.crm.contacts.searchApi&lt;BR /&gt;.doSearch({&lt;BR /&gt;filterGroups: [{&lt;BR /&gt;filters: [{&lt;BR /&gt;propertyName: DEDUPE_PROPERTY,&lt;BR /&gt;operator: 'EQ',&lt;BR /&gt;value: dedupePropValue&lt;BR /&gt;}]&lt;BR /&gt;}]&lt;BR /&gt;})&lt;BR /&gt;.then(searchResults =&amp;gt; {&lt;BR /&gt;let idsToMerge = searchResults.body.results&lt;BR /&gt;.map(object =&amp;gt; object.id)&lt;BR /&gt;.filter(vid =&amp;gt; Number(vid) !== Number(event.object.objectId));&lt;BR /&gt;&lt;BR /&gt;if (idsToMerge.length == 0) {&lt;BR /&gt;console.log('No matching contact, nothing to merge');&lt;BR /&gt;return;&lt;BR /&gt;} else if (idsToMerge.length &amp;gt; 1) {&lt;BR /&gt;console.log(`Found multiple potential contact IDs ${idsToMerge.join(', ')} to merge`);&lt;BR /&gt;throw new Error("Ambiguous merge; more than one matching contact");&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;let idToMerge = idsToMerge[0];&lt;BR /&gt;console.log(`Merging enrolled contact id=${event.object.objectId} into contact id=${idToMerge}`);&lt;BR /&gt;hubspotClient&lt;BR /&gt;.apiRequest({&lt;BR /&gt;method: 'POST',&lt;BR /&gt;path: `/contacts/v1/contact/merge-vids/${idToMerge}`,&lt;BR /&gt;body: {&lt;BR /&gt;vidToMerge: event.object.objectId&lt;BR /&gt;}&lt;BR /&gt;})&lt;BR /&gt;.then(mergeResult =&amp;gt; {&lt;BR /&gt;console.log('Contacts merged!');&lt;BR /&gt;});&lt;BR /&gt;});&lt;BR /&gt;});&lt;BR /&gt;};&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I'm using:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Private App set up as a Secret called DedupePrivateApp&lt;/LI&gt;
&lt;LI&gt;Node.js 16.x&lt;/LI&gt;
&lt;LI&gt;HubSpot Client v8&lt;/LI&gt;
&lt;LI&gt;Property to include in code: Phone number property 'phone'&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Mon, 11 Sep 2023 06:11:08 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/847330#M35795</guid>
      <dc:creator>tcxen</dc:creator>
      <dc:date>2023-09-11T06:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using custom code workflow action to merge contacts based on matching phone number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/855949#M36043</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/75797"&gt;@tcxen&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;I recently used this code and had to remove the body node from&amp;nbsp;contactResult.body.properties and&amp;nbsp;searchResults.body.results &lt;A href="https://github.com/HubSpot/sample-workflow-custom-code/issues/29" target="_blank" rel="noopener"&gt;as mentioned in this issue&lt;/A&gt;. So they become&amp;nbsp;contactResult.properties and&amp;nbsp;searchResults.results.&lt;BR /&gt;&lt;BR /&gt;Hope that helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 09:21:01 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/855949#M36043</guid>
      <dc:creator>MatthewShepherd</dc:creator>
      <dc:date>2023-09-27T09:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using custom code workflow action to merge contacts based on matching phone number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/856461#M36059</link>
      <description>&lt;P&gt;Thanks Matthew!&lt;/P&gt;
&lt;P&gt;That was it. Now working &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thanks for replying.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 01:12:54 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/856461#M36059</guid>
      <dc:creator>tcxen</dc:creator>
      <dc:date>2023-09-28T01:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using custom code workflow action to merge contacts based on matching phone number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/856863#M36065</link>
      <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/1377"&gt;@MatthewShepherd&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":raising_hands:"&gt;🙌&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 16:12:58 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Error-when-using-custom-code-workflow-action-to-merge-contacts/m-p/856863#M36065</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2023-09-28T16:12:58Z</dc:date>
    </item>
  </channel>
</rss>

