⚙ Operations Hub

ChrisChiha
Stratege/Strategin

Using custom code to fetch a contact in a deal

lösung

Hello guys,

 

I would like to use custom code to fetch a certain contact from a deal.

When a deal meets criteria (Note: Deal has 2+contacts in it) => Deal gets enrolled in the workflow => run custom code to fetch a certain contact from within this deal (either by contact id, contact type...)

Thanks,

Chris

1 Akzeptierte Lösung
ChrisChiha
Lösung
Stratege/Strategin

Using custom code to fetch a contact in a deal

lösung

I was able to fetch a contact by adding his email as a property in the deal, and then calling this property from the enrolled deal using my custom code. My next step will be to figure out how to enroll this email that i fetched in a new workflow using the enroll API.

Lösung in ursprünglichem Beitrag anzeigen

11 Antworten
ChrisChiha
Lösung
Stratege/Strategin

Using custom code to fetch a contact in a deal

lösung

I was able to fetch a contact by adding his email as a property in the deal, and then calling this property from the enrolled deal using my custom code. My next step will be to figure out how to enroll this email that i fetched in a new workflow using the enroll API.

ChrisChiha
Stratege/Strategin

Using custom code to fetch a contact in a deal

lösung

Hi @Jonno_Price ,
The thing about the Deal based workflow is it trigger the send email action to all contacts associated to this deal. Even if i do an if branch to check for contact type, when the deal reached the send email action for example, the deal-based workflow send an email to all contacts associated to this deal.

Association labels are not feasible in my current project. 
I was told to use SearchAPI and AsspciationAPI in the custom code to be able to search inside the deal for contacts by filtering certain properties. But it is giving some hard time as i am not a developer.

 

0 Upvotes
Jonno_Price
Ratgeber/-in | Platinum Partner
Ratgeber/-in | Platinum Partner

Using custom code to fetch a contact in a deal

lösung

Ok thanks and could you use a Contact triggered workflow instead of a Deal one? 

This should allow you to only enrol the contact which meets the contact criteria.. A tip is to use an Active list to create the mix of criteria on Deal and Contact level that you want. Then the workflow is a Contact Workflow where enrolment is based on list membership. 


Jonno Price
Growth London Ltd.
Platinum Hubspot Solutions Partner

Did my post help answer your query? Please help the community by marking it as a solution.

0 Upvotes
ChrisChiha
Stratege/Strategin

Using custom code to fetch a contact in a deal

lösung

@Jonno_Price ,
Taking the "email send" action as an example, if we have personalization tokens in the email that are fetched from a deal, Hubspot wont let me integrate this email in a contact-based workflow. (So on the send email action inside the contact-based workflow, the email template can't be chosen.) 
That's why i am stuck with deal-based workflow.

And in many of my emails, personalized content from deals is mandatory in our communications.
So that's why i thought of maybe finding a way to fetch the required contact from the enrolled deal based on certain properties, and then enroll him in another workflow that will take him throughout a new user journey.

0 Upvotes
Jonno_Price
Ratgeber/-in | Platinum Partner
Ratgeber/-in | Platinum Partner

Using custom code to fetch a contact in a deal

lösung

Hi @ChrisChiha - yep run into same issue and my only solve was to create equivalent properties on the contact level and copy the values from deal to contact in order to use in an email. This may or may not be feasible in your case depending on the number of properties.

If you find the solution for calling a specific contact (using code as per your original post) so that you can isolate them in a deal workflow for email purposes pls do share an update here 🙂


Jonno Price
Growth London Ltd.
Platinum Hubspot Solutions Partner

Did my post help answer your query? Please help the community by marking it as a solution.

Jonno_Price
Ratgeber/-in | Platinum Partner
Ratgeber/-in | Platinum Partner

Using custom code to fetch a contact in a deal

lösung

Hi @ChrisChiha

Apologies if I misunderstannd the use case here but don't think custom code is needed? e.g. you simply use the enrollment criteria in a workflow.

If deal meets X criteria and associated contact type = Y then do Z.


Jonno Price
Growth London Ltd.
Platinum Hubspot Solutions Partner

Did my post help answer your query? Please help the community by marking it as a solution.

0 Upvotes
jspencerdav
Mitwirkender/Mitwirkende | Diamond Partner
Mitwirkender/Mitwirkende | Diamond Partner

Using custom code to fetch a contact in a deal

lösung

Are the deals credited by API? Even if not, flexible associations comes to mind as a way to pull an individual contact. 

ChrisChiha
Stratege/Strategin

Using custom code to fetch a contact in a deal

lösung

@jspencerdav 
The deals are created by API. 
I was able to use the below code in the workflow "custom code" action to search for contacts of type customer in my CRM :
 
const hubspot = require('@hubspot/api-client');exports.main = (event, callback) => {  const hubspotClient = new hubspot.Client({
    apiKey: process.env.hapikey
  });  const filter = { propertyName: 'contact_type', operator: 'EQ', value: 'customer' }
  const filterGroup = { filters:    [filter]    } 

const limit = 5
const after = 0

 const conditions = {
    filterGroups: [filterGroup],
    limit,
    after
  }  hubspotClient.crm.contacts.searchApi.doSearch(conditions).then(searchDealResponse => {    var contact_type = 'customer';
    console.log(searchDealResponse.body.results)    callback({
      outputFields: {
        contact_type: contact_type
      }
    });  })    .catch(err => {
      console.error(err);
    });
}

 

This code is returning all contacts in my CRM who have contact type: customer
I would like to implement the search on enrolled deal level only. Can this be done ?

0 Upvotes
yesh_naik
Teilnehmer/-in

Using custom code to fetch a contact in a deal

lösung

@ChrisChiha 
Did you manage to figure this out? 
I can share my expertise with custom codes in workflows.


0 Upvotes
JenBergren
Ratgeber/-in

Using custom code to fetch a contact in a deal

lösung

Thanks for the tag! I do not have the answer but will tag in some other awesome minds from my team: @jspencerdav @jamesle 

@JBurgess @MAnderson42 @VSonne @RemotishAgency 


Thanks!
Jen Bergren
Human-Centered Operations Leader, HubSpot SuperFan, Instructional Design and Lifelong Learning Advocate
Connect with me on Linkedin
JenWeiss
HubSpot Employee
HubSpot Employee

Using custom code to fetch a contact in a deal

lösung

Hi @ChrisChiha , 

 

Thank you for reaching out to us! 

 

I would like to tag in some of our experts into there since they would be able to have some insight @Drew_Cohen , @JenBergren and @jonnoprice . 

 

Best, 

@JenWeiss 

Whether you're a student or a lifelong learner. Join StudentSpot to be inspired.