How can I get call activities by a contacts vid? Or trigger a webhook that sends information like time of call and call duration? I've tested with a workflow webhook based on Call Outcome = Connected. But it doesn't send any information on the call activity that I can see. I've also tried the Time Line endpoint, but it doesn't look like i can get a timeline by Contact record.
This would return the first 500 call engagement records (ID only) associated with the given contact. You could then use the Get Engagement endpoint to request additional information about each of the call engagement records. I don't think you can get engagement records in batches yet (hopefully this will be part of the Engagements API V3, currently marked as in development).
Using a workflow to loop over all existing Contacts and associated Calls in your HubSpot portal is possible, but I don't think this can currently be configured to re-enroll the Contact record if a new call is logged against it. So that'd only be useful from an initial batch processing perspective, which you may prefer to do by interacting directly with HubSpot APIs.
Regardless, I've tested a custom code workflow action (a relatively new HubSpot feature), which returns [1] all call engagement record IDs (max 500) associated with the given contact (as stringified JSON), [2] the most recent call engagement record ID (from the first 500 max associated records) and [3] boolean indicator as to whether more than 500 calls are associated with the given contact. It doesn't really solve your case, but you could build upon it (assuming your portal has access to custom code workflow actions).
/*
Returns engagement record IDs associated with a record of a different object type
Default fromObjectType is "contact"
Default toObjectType is "call"
These can be configured below
Assumptions / limitations
=========================
- Does not support pagination. Defaults to the maximum number of results per page (500)
You can configure this results limit below
If there are more than 500 associated engagement records of the relevant type, output variable paginationFlag will be true
- Assumes you have saved and enabled your hapikey as an environment secret called "HAPIKEY"
- Assumes you have configured data outputs with 3 variables:
1. associatedEngagements (string)
2. recentEngagementId (string)
3. paginationFlag (boolean)
*/
const request = require("request");
exports.main = (event, callback) => {
// SET THESE VARIABLES TO SUIT YOUR CASE
let fromObjectType = "contact";
let recordId = event.object.objectId;
let toObjectType = "call"
let responseLimit = "500"
// ======================
var options = {
method: "GET",
url: "https://api.hubapi.com/crm/v3/objects/" + fromObjectType + "/" + recordId + "/associations/" + toObjectType,
qs: {limit: responseLimit, hapikey: process.env.HAPIKEY},
headers: {accept: 'application/json'},
json: true
};
return new Promise(resolve => {
request(options, function (error, response, body) {
if(!error)
resolve(body);
})
}).then(results => {
// DEBUGGING
//console.log(results);
//console.log(typeof(results));
// =============
let paginationFlag = false;
if (results.results.length == responseLimit) {
paginationFlag = true;
console.log("Returned " + fromObjectType + " may have more than " + responseLimit + " associated engagement records. Consider adding support for pagination.")
}
callback({
outputFields: {
associatedEngagements: JSON.stringify(results),
recentEngagementId: results.results[results.results.length-1].id,
paginationFlag: paginationFlag
}
});
}).catch(err => {
console.error(err);
});
}
Hopefully, that's helpful (or thought-provoking, at the very least). Shout with any follow up questions 😄
This would return the first 500 call engagement records (ID only) associated with the given contact. You could then use the Get Engagement endpoint to request additional information about each of the call engagement records. I don't think you can get engagement records in batches yet (hopefully this will be part of the Engagements API V3, currently marked as in development).
Using a workflow to loop over all existing Contacts and associated Calls in your HubSpot portal is possible, but I don't think this can currently be configured to re-enroll the Contact record if a new call is logged against it. So that'd only be useful from an initial batch processing perspective, which you may prefer to do by interacting directly with HubSpot APIs.
Regardless, I've tested a custom code workflow action (a relatively new HubSpot feature), which returns [1] all call engagement record IDs (max 500) associated with the given contact (as stringified JSON), [2] the most recent call engagement record ID (from the first 500 max associated records) and [3] boolean indicator as to whether more than 500 calls are associated with the given contact. It doesn't really solve your case, but you could build upon it (assuming your portal has access to custom code workflow actions).
/*
Returns engagement record IDs associated with a record of a different object type
Default fromObjectType is "contact"
Default toObjectType is "call"
These can be configured below
Assumptions / limitations
=========================
- Does not support pagination. Defaults to the maximum number of results per page (500)
You can configure this results limit below
If there are more than 500 associated engagement records of the relevant type, output variable paginationFlag will be true
- Assumes you have saved and enabled your hapikey as an environment secret called "HAPIKEY"
- Assumes you have configured data outputs with 3 variables:
1. associatedEngagements (string)
2. recentEngagementId (string)
3. paginationFlag (boolean)
*/
const request = require("request");
exports.main = (event, callback) => {
// SET THESE VARIABLES TO SUIT YOUR CASE
let fromObjectType = "contact";
let recordId = event.object.objectId;
let toObjectType = "call"
let responseLimit = "500"
// ======================
var options = {
method: "GET",
url: "https://api.hubapi.com/crm/v3/objects/" + fromObjectType + "/" + recordId + "/associations/" + toObjectType,
qs: {limit: responseLimit, hapikey: process.env.HAPIKEY},
headers: {accept: 'application/json'},
json: true
};
return new Promise(resolve => {
request(options, function (error, response, body) {
if(!error)
resolve(body);
})
}).then(results => {
// DEBUGGING
//console.log(results);
//console.log(typeof(results));
// =============
let paginationFlag = false;
if (results.results.length == responseLimit) {
paginationFlag = true;
console.log("Returned " + fromObjectType + " may have more than " + responseLimit + " associated engagement records. Consider adding support for pagination.")
}
callback({
outputFields: {
associatedEngagements: JSON.stringify(results),
recentEngagementId: results.results[results.results.length-1].id,
paginationFlag: paginationFlag
}
});
}).catch(err => {
console.error(err);
});
}
Hopefully, that's helpful (or thought-provoking, at the very least). Shout with any follow up questions 😄
Wow @zaklein, thanks so much for the info! I was thinking that the workflow approach would work great, until I ran into the re-enrolment issue you mentioned. I can confirm that it won't re-enroll based on call status. This is definitely helpful. I'm going to try the list associations, followed by get engagement and see if I can grab the info I need. It amy not be very efficient the way I need to use it, but I think it will hold me over until V3 of the engagements API comes out.
Good suggestions on the engagement ids. It looks like i do have some engagement ids that come back. I'm not sure if any of these are call records though. Here's what I'm seeing: notes_last_contacted, hs_email_sends_since_last_engagement, num_notes, notes_last_updated, num_contacted_notes.
One thing I did realize is that with the workflow webhook triggered on Connected Call, I can just timestamp that on my end so I know when the event happened. Which solves one piece for me for sure. It looks like I can't retrigger a workflow using that criteria though and I'd like to grab all of the calls in my app.