<?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: Duplicate contact if the contact grater than 3 in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Duplicate-contact-if-the-contact-grater-than-3/m-p/1045013#M76871</link>
    <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101258"&gt;@Teun&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example is if in my Contact i same conatct with more than 3 conatct available i am going to marge&amp;nbsp; all cotact with single contact .&lt;/P&gt;&lt;P&gt;I am in using this code but when the conatct is more 2 then this code throwing error.&lt;/P&gt;&lt;P&gt;bellow the code here&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;const PROPERTY_USED_TO_DEDUPE_CONTACTS = 'phone';&lt;/P&gt;&lt;P&gt;exports.main = async (event, callback) =&amp;gt; {&lt;BR /&gt;const hubspotClient = new hubspot.Client({ accessToken: '' });&lt;/P&gt;&lt;P&gt;try {&lt;BR /&gt;console.log("Phone number:", PROPERTY_USED_TO_DEDUPE_CONTACTS);&lt;/P&gt;&lt;P&gt;const contactResult = await hubspotClient.crm.contacts.basicApi.getById(event.object.objectId, [PROPERTY_USED_TO_DEDUPE_CONTACTS]);&lt;/P&gt;&lt;P&gt;console.log("All contact properties:", contactResult.properties);&lt;/P&gt;&lt;P&gt;let dedupePropValue = contactResult.properties[PROPERTY_USED_TO_DEDUPE_CONTACTS];&lt;/P&gt;&lt;P&gt;if (!dedupePropValue) {&lt;BR /&gt;console.log(`No value found for ${PROPERTY_USED_TO_DEDUPE_CONTACTS}`);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;console.log("Phone number:", dedupePropValue);&lt;/P&gt;&lt;P&gt;// Ensure the dedupe property is not empty or invalid&lt;BR /&gt;if (!dedupePropValue) {&lt;BR /&gt;console.log(`No value found for ${PROPERTY_USED_TO_DEDUPE_CONTACTS}, skipping deduplication.`);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;console.log(`Looking for duplicates based on ${PROPERTY_USED_TO_DEDUPE_CONTACTS} = ${dedupePropValue}`);&lt;BR /&gt;// Search for duplicate contacts&lt;BR /&gt;const searchResults = await hubspotClient.crm.contacts.searchApi.doSearch({&lt;BR /&gt;filterGroups: [{&lt;BR /&gt;filters: [{&lt;BR /&gt;propertyName: PROPERTY_USED_TO_DEDUPE_CONTACTS,&lt;BR /&gt;operator: 'EQ',&lt;BR /&gt;value: dedupePropValue&lt;BR /&gt;}]&lt;BR /&gt;}]&lt;BR /&gt;});&lt;BR /&gt;// Collect IDs of contacts that match the dedupe property but aren't the current contact&lt;BR /&gt;let idsToMerge = searchResults.results&lt;BR /&gt;.map(object =&amp;gt; object.id)&lt;BR /&gt;.filter(vid =&amp;gt; Number(vid) !== Number(event.object.objectId));&lt;/P&gt;&lt;P&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;// Merge the contacts&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;const mergeResult = await hubspotClient.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;console.log('Contacts merged successfully!');&lt;BR /&gt;} catch (error) {&lt;BR /&gt;console.error('Error during contact deduplication:', error.message);&lt;BR /&gt;}&lt;BR /&gt;};&lt;/P&gt;</description>
    <pubDate>Tue, 24 Sep 2024 06:09:46 GMT</pubDate>
    <dc:creator>AGupta21</dc:creator>
    <dc:date>2024-09-24T06:09:46Z</dc:date>
    <item>
      <title>Duplicate contact if the contact grater than 3</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Duplicate-contact-if-the-contact-grater-than-3/m-p/1043779#M76796</link>
      <description>&lt;P&gt;We team I am write custom&amp;nbsp; code to marge dublicate vai API but i got error while there contact have &amp;gt;2 contact as same conatct in my hubspot I am using this API&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please provide me the solution to marge more than 2 conatct via API&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 13:59:50 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Duplicate-contact-if-the-contact-grater-than-3/m-p/1043779#M76796</guid>
      <dc:creator>AGupta21</dc:creator>
      <dc:date>2024-09-20T13:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate contact if the contact grater than 3</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Duplicate-contact-if-the-contact-grater-than-3/m-p/1043997#M76814</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/776236"&gt;@AGupta21&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The question is a bit hard to answer without an example of your code, however;&lt;/P&gt;
&lt;P&gt;This can not be achieved with a single call, so you would first have to merge the first two contacts, and then merge the last one in an additional API call. This should be achievable with a small for loop in your code.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 19:47:00 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Duplicate-contact-if-the-contact-grater-than-3/m-p/1043997#M76814</guid>
      <dc:creator>Teun</dc:creator>
      <dc:date>2024-09-20T19:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate contact if the contact grater than 3</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Duplicate-contact-if-the-contact-grater-than-3/m-p/1045013#M76871</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101258"&gt;@Teun&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example is if in my Contact i same conatct with more than 3 conatct available i am going to marge&amp;nbsp; all cotact with single contact .&lt;/P&gt;&lt;P&gt;I am in using this code but when the conatct is more 2 then this code throwing error.&lt;/P&gt;&lt;P&gt;bellow the code here&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;const PROPERTY_USED_TO_DEDUPE_CONTACTS = 'phone';&lt;/P&gt;&lt;P&gt;exports.main = async (event, callback) =&amp;gt; {&lt;BR /&gt;const hubspotClient = new hubspot.Client({ accessToken: '' });&lt;/P&gt;&lt;P&gt;try {&lt;BR /&gt;console.log("Phone number:", PROPERTY_USED_TO_DEDUPE_CONTACTS);&lt;/P&gt;&lt;P&gt;const contactResult = await hubspotClient.crm.contacts.basicApi.getById(event.object.objectId, [PROPERTY_USED_TO_DEDUPE_CONTACTS]);&lt;/P&gt;&lt;P&gt;console.log("All contact properties:", contactResult.properties);&lt;/P&gt;&lt;P&gt;let dedupePropValue = contactResult.properties[PROPERTY_USED_TO_DEDUPE_CONTACTS];&lt;/P&gt;&lt;P&gt;if (!dedupePropValue) {&lt;BR /&gt;console.log(`No value found for ${PROPERTY_USED_TO_DEDUPE_CONTACTS}`);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;console.log("Phone number:", dedupePropValue);&lt;/P&gt;&lt;P&gt;// Ensure the dedupe property is not empty or invalid&lt;BR /&gt;if (!dedupePropValue) {&lt;BR /&gt;console.log(`No value found for ${PROPERTY_USED_TO_DEDUPE_CONTACTS}, skipping deduplication.`);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;console.log(`Looking for duplicates based on ${PROPERTY_USED_TO_DEDUPE_CONTACTS} = ${dedupePropValue}`);&lt;BR /&gt;// Search for duplicate contacts&lt;BR /&gt;const searchResults = await hubspotClient.crm.contacts.searchApi.doSearch({&lt;BR /&gt;filterGroups: [{&lt;BR /&gt;filters: [{&lt;BR /&gt;propertyName: PROPERTY_USED_TO_DEDUPE_CONTACTS,&lt;BR /&gt;operator: 'EQ',&lt;BR /&gt;value: dedupePropValue&lt;BR /&gt;}]&lt;BR /&gt;}]&lt;BR /&gt;});&lt;BR /&gt;// Collect IDs of contacts that match the dedupe property but aren't the current contact&lt;BR /&gt;let idsToMerge = searchResults.results&lt;BR /&gt;.map(object =&amp;gt; object.id)&lt;BR /&gt;.filter(vid =&amp;gt; Number(vid) !== Number(event.object.objectId));&lt;/P&gt;&lt;P&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;// Merge the contacts&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;const mergeResult = await hubspotClient.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;console.log('Contacts merged successfully!');&lt;BR /&gt;} catch (error) {&lt;BR /&gt;console.error('Error during contact deduplication:', error.message);&lt;BR /&gt;}&lt;BR /&gt;};&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2024 06:09:46 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Duplicate-contact-if-the-contact-grater-than-3/m-p/1045013#M76871</guid>
      <dc:creator>AGupta21</dc:creator>
      <dc:date>2024-09-24T06:09:46Z</dc:date>
    </item>
  </channel>
</rss>

