CMS Development

JHowardAdapt
Membre

Using the api client merge endpoint in custom code

Résolue

Hi,

 

I am trying to use the new merge endpoint from the api client within a custom code block of a workflow but can't seem to figure out how to do it, if it is even possible. 

I have called vairous other endpoints from the client like so: 

 

await hubspotClient.crm.companies.basicApi.getById(event.object.objectId, ["domain"]).then(results => {
})

 

But I am not sure what the path or the parameters are for the merge endpoint. The merge endpoint can be found in the github repo https://github.com/HubSpot/hubspot-api-nodejs/blob/master/codegen/crm/companies/apis/PublicObjectApi... 

 

Can someone please help me out with how to use this? 

 

Thanks

J Howard

0 Votes
1 Solution acceptée
LMeert
Solution
Guide | Partenaire solutions Platinum
Guide | Partenaire solutions Platinum

Using the api client merge endpoint in custom code

Résolue

Hi @JHowardAdapt@Jaycee_Lewis,

 

You can find here the documentation for merging two companies.

There's the nodeJs example that matches what you've done so far.
You're basically passing two variables : the primary Id as well as the object Id to merge with.

Hope this helps !
If it does, please consider marking this answer as a solution 🙂

 

Best,

Ludwig

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

Voir la solution dans l'envoi d'origine

0 Votes
6 Réponses
AbdelMOULIDA
Contributeur

Using the api client merge endpoint in custom code

Résolue

Hello @JHowardAdapt !

 

Were you able to merge your companies by domain name?
I'm trying to do the same thing on my side but I can't.

 

Please share with use your code if you were able to make the merge, thank you.

 

Abdelilah

0 Votes
JHowardAdapt
Membre

Using the api client merge endpoint in custom code

Résolue

I had to loop through each company in my account and use this endpoint for each company to see if it's domain existed multiple times in the system: 

 

  const filter = { propertyName: 'domain', operator: 'EQ', value: companyDomain }
  const filterGroup = { filters: [filter] }
  const sort = JSON.stringify({ propertyName: 'createdate', direction: 'DESCENDING' })
  const properties = propertiesArray
  const limit = 100
  const after = 0

  const publicObjectSearchRequest = {
      filterGroups: [filterGroup],
      sorts: [sort],
      properties,
      limit,
      after,
  }

const result : any =  await hubspotRequest("POST", "/crm/v3/objects/companies/search", publicObjectSearchRequest)

If this search returned more than 1 company I would merge all of the companies into the one that I identified as being the main company (this is based on our own company logic, so you will need to decide your own).  For each company that is returned and is not idenfied as the main one I used this endpoint to merge them into the main company: 

 

        const body = {
            "primaryObjectId": primaryId,
            "objectIdToMerge": toMergeId
        }
    
    return await hubspotRequest("POST", "/crm/v3/objects/companies/merge", body)

Depending on how many companies you have in your Hubpot this could take a long time, I used a stand alone script and ran it on my machine for a day. But I had 100k duplicates. 

 

Also please be aware that the code samples above include methods like hubspotRequest that are my own methods that call my Hubspot api. 

0 Votes
LMeert
Solution
Guide | Partenaire solutions Platinum
Guide | Partenaire solutions Platinum

Using the api client merge endpoint in custom code

Résolue

Hi @JHowardAdapt@Jaycee_Lewis,

 

You can find here the documentation for merging two companies.

There's the nodeJs example that matches what you've done so far.
You're basically passing two variables : the primary Id as well as the object Id to merge with.

Hope this helps !
If it does, please consider marking this answer as a solution 🙂

 

Best,

Ludwig

Agence Mi4 - Data DrivenCTO @ Mi4
Hubspot Platinum Partner and Integration Expert

Passionate human, very curious about everything data and automation.

Any problem with Hubspot you need help solving ?

Let me know !

0 Votes
JHowardAdapt
Membre

Using the api client merge endpoint in custom code

Résolue

Hi @LMeert Ludwig,

 

I actually end up getting an undefined error for that endpoint when using the exact example from the documentation you suggest.

 

"TypeError: Cannot read property 'merge' of undefined"

 

It looks like the publicObjectApi isn't accessible in the hubspot client? 

 

I am wondering if this is maybe because it's a relatively new endpoint? 

 

 

0 Votes
JHowardAdapt
Membre

Using the api client merge endpoint in custom code

Résolue

Hi Ludwig,

 

Thanks for this, it seems I was being stupid and didnt notice the node tab on the code example 😣

Jaycee_Lewis
Gestionnaire de communauté
Gestionnaire de communauté

Using the api client merge endpoint in custom code

Résolue

Hi, @JHowardAdapt 👋 Thanks for reaching out. Let's see if our community has any experience here — @JBeatty @LMeert, do you have any insight into how @JHowardAdapt can accomplish their goal? 

 

Thank you! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Votes