⚙ Operations Hub

DEstillero
Contributor

Copy Contact Association Label to Contact Property

SOLVE

Hello,

 

I'd like to know if it is possible to get the string of the association label on a Contact that is associated with a deal. Then using that string to copy it over to a Contact property. 

 

I've got the below custom code where I'm able to get the Associated Contact's details however I'm unsure on how to get the Associated Contact's Association Label. I would then like to save that value onto a variable which I will use to copy onto the Contact property.

 

Any assistance on this would be great! 

 

hubspotClient.crm.deals.associationsApi.getAll(event.object.objectId, 'contacts').then((results) => {
let contactPromises = results.body.results.map(item => {
return hubspotClient.crm.contacts.basicApi.getById(item.id, ['hs_object_id', 'hs_buying_role', 'firstname', 'lastname', 'champion']).then(results => {
return results.body
})
})

Promise.all(contactPromises).then(resultsArray => {
console.log(resultsArray)


resultsArray.forEach(item => {
let buying_role = item.properties.hs_buying_role
console.log(buying_role)
let firstname = item.properties.firstname
console.log(firstname)
let lastname = item.properties.lastname
console.log(lastname)
})
})
})

0 Upvotes
1 Accepted solution
PamCotton
Solution
Community Manager
Community Manager

Copy Contact Association Label to Contact Property

SOLVE

Hey @DEstillero, thank you for posting in our Community!

 

You can use the HubSpot API to retrieve the association label from a contact associated with a deal, and then update the contact property with that label.
 For example, start by using the deals.associationsApi.getAll method to get contacts associated with a deal. After you can retrieve the details and association label for each contact using contacts.basicApi.getById and deals.associationsApi.getAssociation. And update the contact property with the retrieved association label using contacts.basicApi.update

 

I hope this helps,

Kindly,

Pam

Você sabia que a Comunidade está disponível em outros idiomas?
Participe de conversas regionais, alterando suas configurações de idioma !


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !




View solution in original post

5 Replies 5
RThomas11
Member

Copy Contact Association Label to Contact Property

SOLVE

I think the approach is to use the crm.deals.associationsApi.getAll to get the association IDs then use the crm.deals.associationsApi.getById to get the association lable.

0 Upvotes
PamCotton
Solution
Community Manager
Community Manager

Copy Contact Association Label to Contact Property

SOLVE

Hey @DEstillero, thank you for posting in our Community!

 

You can use the HubSpot API to retrieve the association label from a contact associated with a deal, and then update the contact property with that label.
 For example, start by using the deals.associationsApi.getAll method to get contacts associated with a deal. After you can retrieve the details and association label for each contact using contacts.basicApi.getById and deals.associationsApi.getAssociation. And update the contact property with the retrieved association label using contacts.basicApi.update

 

I hope this helps,

Kindly,

Pam

Você sabia que a Comunidade está disponível em outros idiomas?
Participe de conversas regionais, alterando suas configurações de idioma !


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !




DEstillero
Contributor

Copy Contact Association Label to Contact Property

SOLVE

Hi @PamCotton 

 

That make sense to me thank you! However, I'm unfamiliar with using deals.associationsApi.getAssociation, are you able to show me an example of where it is used?

 

Kind regards,

Dennis

0 Upvotes
DavidVoigt
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

Copy Contact Association Label to Contact Property

SOLVE

Hi @DEstillero happy to help you out!

For example,

const objectType = "DEAL";
const objectId = "your_deal_id";
const toObjectType = "CONTACT";
const after = undefined;
const limit = 500;


Then your API call looks like this:

const apiResponse = await hubspotClient.crm.associations.v4.basicApi.getPage(objectType, objectId, toObjectType, after, limit);


Which should return an array of results like this:

{
  "results": [    
    {
      "toObjectId": 25262191424,
      "associationTypes": [
        {
          "category": "USER_DEFINED",
          "typeId": 170,
          "label": "Decision Maker"
        },
        {
          "category": "HUBSPOT_DEFINED",
          "typeId": 3,
          "label": null
        }
      ]
    }
  ]
} 

 
It includes all contacts associated with the deal, including the flexible association type id and its label.

DEstillero
Contributor

Copy Contact Association Label to Contact Property

SOLVE

Great thanks David! Appreciate this and I will try it out! 

0 Upvotes