Created
May 5, 2022 09:15
-
-
Save jackcoldrick90/03366967f400f23eb27c4d49b53177a6 to your computer and use it in GitHub Desktop.
Custom Coded Action to create an engagement (NOTE) and associate to a CONTACT record
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Custom Coded Action to create an engagement (NOTE) and associate to a CONTACT record | |
const axios = require('axios'); | |
exports.main = async (event, callback) => { | |
//1. Create Engagement | |
var body = 'This engagement was created using a custom coded workflow action! A feature exclusive to Operations Hub Professional'; // can be customised | |
axios.post('https://api.hubapi.com/crm/v3/objects/notes?hapikey=' + process.env.HAPIKEY, { | |
"properties": { | |
"hs_timestamp": Date.now(), // Current time/date | |
"hs_note_body": body // Body of the note | |
} | |
}) | |
.then(function(response) { | |
//2. Associate Engagement to the currently enrolled object. | |
var engagementID = response.data.id; | |
axios({ | |
method: 'put', | |
url: 'https://api.hubapi.com/crm/v3/objects/notes/' + engagementID + '/associations/contact/' + event.object.objectId + '/NOTE_TO_CONTACT?hapikey=' + process.env.HAPIKEY, | |
headers: { | |
'Content-Type': 'application/json' | |
} | |
}) | |
.then(function(response) { | |
console.log("RESPONSE: " + response) | |
}) | |
.catch(err => { | |
console.log('Error: ' + err.message); | |
}) | |
}) | |
.catch(err => { | |
console.log('Error: ' + err.message); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment