Created
November 9, 2022 22:14
-
-
Save HubSpotHanevold/f207dbc45a9242cba336a10270f158b1 to your computer and use it in GitHub Desktop.
A way to retrieve the cancel or reschedule links from a meeting body
This file contains hidden or 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
var axios = require('axios'); | |
exports.main = async (event, callback) => { | |
const hs_object_id = event.inputFields['hs_object_id']; | |
var config = { | |
method: 'get', | |
url: 'https://api.hubapi.com/crm/v4/objects/contact/' + hs_object_id +'/associations/meetings', | |
headers: { | |
'Authorization': 'Bearer ' + process.env.CalendarLink | |
} | |
}; | |
axios(config) | |
.then(function (response) { | |
// console.log(JSON.stringify(response.data)); | |
let result = JSON.stringify(response.data); | |
const obj = JSON.parse(result); | |
let meetings = obj.results; | |
let count_meetings = meetings.length; | |
for (let i = 0; i < count_meetings; i++) { | |
let meeting_id = obj.results[i].toObjectId; | |
var next_config = { | |
method: 'get', | |
url: 'https://api.hubapi.com/crm/v3/objects/meetings/' + meeting_id + '?properties=hs_meeting_end_time%2C%20hs_meeting_body%2C%20hs_activity_type', | |
headers: { | |
'Authorization': 'Bearer ' + process.env.CalendarLink | |
} | |
}; | |
axios(next_config) | |
.then(function (next_response) { | |
let next_result = JSON.stringify(next_response.data); | |
const next_obj = JSON.parse(next_result); | |
// console.log(next_obj); | |
let meeting_type = next_obj.properties.hs_activity_type; | |
// console.log(meeting_type); | |
if(meeting_type == 'Intern Interview #1') { | |
let meeting_body = next_obj.properties.hs_meeting_body; | |
let text_string = meeting_body.split("<li>Cancel: ")[1]; | |
let cancel_link_split = text_string.split("amp;ms=1")[0]; | |
let cancel_link = cancel_link_split + '&ms=1'; | |
let reschedule_link = cancel_link.replace("cancelId", "rescheduleId"); | |
// console.log(cancel_link); | |
// console.log(reschedule_link); | |
callback({ | |
outputFields: { | |
reschedule_link: reschedule_link, | |
cancel_link: cancel_link | |
} | |
}); | |
} | |
}) | |
} | |
}) | |
.catch(function (error) { | |
console.log(error); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment