<?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: Need help, code doesn't work in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Need-help-code-doesn-t-work/m-p/808725#M80254</link>
    <description>&lt;P&gt;When testing even after making the changes you suggested I'm still getting the same to me, meaningless error message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Kineticmedic_0-1687009333733.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/93145iB2BD910EC436FDF0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Kineticmedic_0-1687009333733.png" alt="Kineticmedic_0-1687009333733.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 17 Jun 2023 13:42:21 GMT</pubDate>
    <dc:creator>Kineticmedic</dc:creator>
    <dc:date>2023-06-17T13:42:21Z</dc:date>
    <item>
      <title>Need help, code doesn't work</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Need-help-code-doesn-t-work/m-p/808470#M80252</link>
      <description>&lt;P&gt;I'm trying to modify the template provided for deduplicating contact records to allow it to deduplicate company records, but as the code appears to have been built against the V1 API, not the V3 which is what documentation references, plus my general unfamiliarity with node.js (I'm a C++ boy) I'm stumped what's going wrong and support doesn't want to help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my code as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;/**
 * This custom code action removes duplicate contacts based on a specific contact property
 */

// Import required libraries
const hubspot = require('@hubspot/api-client');

/**
 * How to access HubSpot's client to make API
 * 1) Create a Private App: https://developers.hubspot.com/docs/api/private-apps
 * 2) Create a Secret using your Private App's access token via the "Secrets" dropdown above
 * 3) Insert your secret below, replacing "YOUR_PRIVATE_APP_ACCESS_TOKEN" with the name of your Secret
 */
const HUBSPOT_PRIVATE_APP_ACCESS_TOKEN = process.env.spoonybard;

// By default, phone numbers are used to dedupe contacts (i.e. 2 contacts with the same phone number are merged together)
// Change this property if you would like to use a different property to dedupe contacts with 
const PROPERTY_USED_TO_DEDUPE_CONTACTS = 'company name';

exports.main = (event, callback) =&amp;gt; {
  const hubspotClient = new hubspot.Client({ accessToken: HUBSPOT_PRIVATE_APP_ACCESS_TOKEN });

  hubspotClient.crm.companies.basicApi
    .getById(event.object.objectId, [PROPERTY_USED_TO_DEDUPE_CONTACTS])
    .then(companyResult =&amp;gt; {
      let dedupePropValue = companyResult.body.properties[PROPERTY_USED_TO_DEDUPE_CONTACTS];

      console.log(`Looking for duplicates based on ${PROPERTY_USED_TO_DEDUPE_CONTACTS} = ${dedupePropValue}`);
      hubspotClient.crm.companies.searchApi.doSearch({
          filterGroups: [{
            filters: [{
              propertyName: PROPERTY_USED_TO_DEDUPE_CONTACTS,
              operator: 'EQ',
              value: dedupePropValue
            }]
          }]
        })
        .then(searchResults =&amp;gt; {
          let idsToMerge = searchResults.body.results
            .map(object =&amp;gt; object.id)
            .filter(vid =&amp;gt; Number(vid) !== Number(event.object.objectId));

          if (idsToMerge.length == 0) {
            console.log('No matching company, nothing to merge');
            return;
          } else if (idsToMerge.length &amp;gt; 1) {
            console.log(`Found multiple potential company IDs ${idsToMerge.join(', ')} to merge`);
            throw new Error("Ambiguous merge; more than one matching company");
          }

          let idToMerge = idsToMerge[0];
          console.log(`Merging enrolled company id=${event.object.objectId} into company id=${idToMerge}`);
          hubspotClient
            .apiRequest({
              method: 'POST',
              path: `/crm/v3/objects/companies/merge/${idToMerge}`,
              body: {
                vidToMerge: event.object.objectId
              }
            })
            .then(mergeResult =&amp;gt; {
              console.log('Companies merged!');
            });
        });
    });
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any and all help appriciated as we have only a few days left to resolve this and fix what was a bad data merge caused by a 3rd party and I'm not really even a developer, rather the only resource with spare time to try.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 14:50:23 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Need-help-code-doesn-t-work/m-p/808470#M80252</guid>
      <dc:creator>Kineticmedic</dc:creator>
      <dc:date>2023-06-16T14:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need help, code doesn't work</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Need-help-code-doesn-t-work/m-p/808677#M80253</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/585578"&gt;@Kineticmedic&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; Thanks for stepping up and trying to tackle this challenge. I'd like to invite some of our community members to the conversation — hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/20405"&gt;@himanshurauthan&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/241684"&gt;@ChrisoKlepke&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/144301"&gt;@taran42&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/551647"&gt;@andreaska&lt;/a&gt;, do you have any troubleshooting tips for&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/585578"&gt;@Kineticmedic&lt;/a&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two things I have to offer off of the top of my head are:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Make sure you are using the internal value and not the label for the Contact property you are using. For example, in Contacts &amp;gt; Properties &amp;gt; Company Name, we can see the internal value for this property is &lt;STRONG&gt;company&lt;/STRONG&gt;, not &lt;EM&gt;company name&lt;/EM&gt; or &lt;EM&gt;&lt;EM&gt;company_name&lt;BR /&gt;&lt;/EM&gt;&lt;/EM&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CleanShot 2023-06-16 at 17.45.30.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/93143iA9A0A2AD139F5D08/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CleanShot 2023-06-16 at 17.45.30.png" alt="CleanShot 2023-06-16 at 17.45.30.png" /&gt;&lt;/span&gt;
&lt;P&gt; &lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;For the merge request body, can you try the following format?&lt;BR /&gt;&lt;LI-CODE lang="javascript"&gt;hubspotClient.apiRequest({
    method: 'POST',
    path: `/crm/v3/objects/companies/${event.object.objectId}/merge-vids`,
    body: {
      primaryObjectId: idToMerge,
      objectIdToMerge: event.object.objectId
    }
})
&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI&gt;I'm not seeing any catch blocks to handle any failures from the API calls. Consider adding a &lt;CODE&gt;.catch(error =&amp;gt; { console.log(error) })&lt;/CODE&gt; after every API call to catch and log the errors for debugging&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Thank you for the extra details! — Jaycee&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 23:53:31 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Need-help-code-doesn-t-work/m-p/808677#M80253</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2023-06-16T23:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need help, code doesn't work</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Need-help-code-doesn-t-work/m-p/808725#M80254</link>
      <description>&lt;P&gt;When testing even after making the changes you suggested I'm still getting the same to me, meaningless error message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Kineticmedic_0-1687009333733.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/93145iB2BD910EC436FDF0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Kineticmedic_0-1687009333733.png" alt="Kineticmedic_0-1687009333733.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jun 2023 13:42:21 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Need-help-code-doesn-t-work/m-p/808725#M80254</guid>
      <dc:creator>Kineticmedic</dc:creator>
      <dc:date>2023-06-17T13:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need help, code doesn't work</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Need-help-code-doesn-t-work/m-p/810786#M80255</link>
      <description>&lt;P&gt;&amp;nbsp;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/585578"&gt;@Kineticmedic&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Three things:&lt;/P&gt;&lt;P&gt;1. When using promises, ensure you provide the `catch`-blocks.&lt;/P&gt;&lt;P&gt;2. In your final promise resolving function call the `callback` function.&lt;/P&gt;&lt;P&gt;3. Do not access the `body` property of the result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Review the example code below to get another starting point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;const &lt;/SPAN&gt;hubspot = require(&lt;SPAN&gt;'@hubspot/api-client'&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;exports.&lt;SPAN&gt;main &lt;/SPAN&gt;= (event&lt;SPAN&gt;, &lt;/SPAN&gt;callback) =&amp;gt; {&lt;BR /&gt;    &lt;SPAN&gt;const &lt;/SPAN&gt;PROPERTY_USED_TO_DEDUPE_CONTACTS = &lt;SPAN&gt;'name'&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    const &lt;/SPAN&gt;hubspotClient = &lt;SPAN&gt;new &lt;/SPAN&gt;hubspot.Client({&lt;SPAN&gt;accessToken&lt;/SPAN&gt;: process.env.HUBSPOT_API_ACCESS_TOKEN})&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    hubspotClient.crm.companies.basicApi.getById(&lt;SPAN&gt;4370248339&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;[&lt;SPAN&gt;'name'&lt;/SPAN&gt;]).&lt;SPAN&gt;then&lt;/SPAN&gt;(companyResult =&amp;gt; {&lt;BR /&gt;        &lt;SPAN&gt;const &lt;/SPAN&gt;dedupePropValue = companyResult.properties[PROPERTY_USED_TO_DEDUPE_CONTACTS]&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;console&lt;/SPAN&gt;.&lt;SPAN&gt;log&lt;/SPAN&gt;(&lt;SPAN&gt;`Looking for duplicates based on &lt;/SPAN&gt;${PROPERTY_USED_TO_DEDUPE_CONTACTS}&lt;SPAN&gt; = &lt;/SPAN&gt;${dedupePropValue}&lt;SPAN&gt;`&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;        hubspotClient.crm.companies.searchApi.doSearch({&lt;BR /&gt;            &lt;SPAN&gt;filterGroups&lt;/SPAN&gt;: [{&lt;BR /&gt;                &lt;SPAN&gt;filters&lt;/SPAN&gt;: [{&lt;BR /&gt;                    &lt;SPAN&gt;propertyName&lt;/SPAN&gt;: PROPERTY_USED_TO_DEDUPE_CONTACTS&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;                    &lt;SPAN&gt;operator&lt;/SPAN&gt;: &lt;SPAN&gt;'EQ'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;                    &lt;SPAN&gt;value&lt;/SPAN&gt;: dedupePropValue&lt;BR /&gt;                }]&lt;BR /&gt;            }]&lt;BR /&gt;        })&lt;BR /&gt;            .&lt;SPAN&gt;then&lt;/SPAN&gt;(searchResults =&amp;gt; {&lt;BR /&gt;                &lt;SPAN&gt;// add further code here&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;                // final call here&lt;BR /&gt;                callback({})&lt;BR /&gt;            }).&lt;SPAN&gt;catch&lt;/SPAN&gt;(ex =&amp;gt; {&lt;BR /&gt;            console.error(ex)&lt;BR /&gt;        })&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;    }).&lt;SPAN&gt;catch&lt;/SPAN&gt;(ex =&amp;gt; {&lt;BR /&gt;        console.error(ex)&lt;BR /&gt;    })&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;}&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&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;</description>
      <pubDate>Thu, 22 Jun 2023 14:20:41 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Need-help-code-doesn-t-work/m-p/810786#M80255</guid>
      <dc:creator>andreaska</dc:creator>
      <dc:date>2023-06-22T14:20:41Z</dc:date>
    </item>
  </channel>
</rss>

