Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertainslie/8234976839aee86c6eeb6da8d3ee9db9 to your computer and use it in GitHub Desktop.
Save robertainslie/8234976839aee86c6eeb6da8d3ee9db9 to your computer and use it in GitHub Desktop.

Use this code in HubSpot Operations Hub Custom Coded Action to dynamically set a Salesforce campaign member status, ideally upon conversion for any tracked contact that visits a page where the campaign ID is in the URL. This utilizes a combination of tools.

Note: it is recommended to use a third party integration (such as Integromat) to handle Salesforce authentication.

For a video overview of the solution, watch here: https://www.loom.com/embed/f328e82747764483b565a908d4a48dc1

const hubspot = require('@hubspot/api-client');
const axios = require('axios')
exports.main = (event, callback) => {
// secrets can be accessed via environment variables
// make sure to add your HAPIKEY under "Secrets management" above
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
hubspotClient.crm.contacts.basicApi.getById(event.object.objectId, ["recent_salesforce_campaign",'email','salesforceleadid','salesforcecontactid'])
.then(results => {
let recent_salesforce_campaign = results.body.properties.recent_salesforce_campaign;
let email = results.body.properties.email;
let salesforceleadid = results.body.properties.salesforceleadid
let data = {recent_salesforce_campaign:recent_salesforce_campaign,email:email,salesforceleadid:salesforceleadid}
console.log(data)
return data
}).then(data => {
//Create a webhook listener in an iPaaS service such as Integromat and customize the POST request URL
axios.post('https://SOME_WEBHOOK_URL', {
recent_salesforce_campaign: recent_salesforce_campaign,
email: data.email,
salesforceleadid: data.salesforceleadid
})
.then(function (response) {
console.log(response.body);
})
.catch(function (error) {
console.log(error);
});
})
.catch(err => {
console.error(err);
});
}
@evelli26
Copy link

Curious what the specific workaround is for the contact vs lead id issue you mentioned in the video overview?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment