I presume you are planning on using the Hubspot API and custom code workflow actions for this. So I would suggest using the Meetings Engagements Search endpoint. First I would assign today's date/time to a variable. You can then filter by association with the company or contact and hs_meeting_start_time greater than the date variable you assigned earlier. Make sure to sort by hs_meeting_start_time ascending and set the limit to 1.
This will return just the one meeting which is the next meeting associated with that company or contact. You can then extract the hs_meeting_start_time from the results and format it as you like.
This way you don't have to pull a load of meetings to loop through and are less likely to encounter edge cases when a meeting might not be scheduled in the next 14 days. You may also want to adjust the code or the workflow to handle cases where there are no future-dated meetings.
I just tested it and this seems to work for me:
var http = require("https");
exports.main = async (event, callback) => {
var date = new Date();
var start_date_time;
var options = {
method: "POST",
hostname: "api.hubapi.com",
port: null,
path: "/crm/v3/objects/meetings/search",
headers: {
accept: "application/json",
"content-type": "application/json",
authorization: "Bearer " + process.env.{{Your Secret}},
},
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
var responseBody = JSON.parse(body.toString());
if (responseBody.results && responseBody.results[0]) {
start_date_time = responseBody.results[0].properties.hs_meeting_start_time;
}
callback({
outputFields: {
start_date_time: start_date_time,
},
});
});
});
req.write(
JSON.stringify({
filterGroups: [
{
filters: [
{
propertyName: "associations.contact",
operator: "EQ",
value: event.inputFields["id"]
},
{
propertyName: "hs_meeting_start_time",
operator: "GTE",
value: date
},
],
},
],
sorts: [
{
propertyName: "hs_meeting_start_time",
direction: "ASCENDING",
},
],
properties: ["hs_meeting_start_time"],
limit: 1,
})
);
req.end();
};
Hope this helps and feel free to reach out if you encounter any problems.
I presume you are planning on using the Hubspot API and custom code workflow actions for this. So I would suggest using the Meetings Engagements Search endpoint. First I would assign today's date/time to a variable. You can then filter by association with the company or contact and hs_meeting_start_time greater than the date variable you assigned earlier. Make sure to sort by hs_meeting_start_time ascending and set the limit to 1.
This will return just the one meeting which is the next meeting associated with that company or contact. You can then extract the hs_meeting_start_time from the results and format it as you like.
This way you don't have to pull a load of meetings to loop through and are less likely to encounter edge cases when a meeting might not be scheduled in the next 14 days. You may also want to adjust the code or the workflow to handle cases where there are no future-dated meetings.
I just tested it and this seems to work for me:
var http = require("https");
exports.main = async (event, callback) => {
var date = new Date();
var start_date_time;
var options = {
method: "POST",
hostname: "api.hubapi.com",
port: null,
path: "/crm/v3/objects/meetings/search",
headers: {
accept: "application/json",
"content-type": "application/json",
authorization: "Bearer " + process.env.{{Your Secret}},
},
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
var responseBody = JSON.parse(body.toString());
if (responseBody.results && responseBody.results[0]) {
start_date_time = responseBody.results[0].properties.hs_meeting_start_time;
}
callback({
outputFields: {
start_date_time: start_date_time,
},
});
});
});
req.write(
JSON.stringify({
filterGroups: [
{
filters: [
{
propertyName: "associations.contact",
operator: "EQ",
value: event.inputFields["id"]
},
{
propertyName: "hs_meeting_start_time",
operator: "GTE",
value: date
},
],
},
],
sorts: [
{
propertyName: "hs_meeting_start_time",
direction: "ASCENDING",
},
],
properties: ["hs_meeting_start_time"],
limit: 1,
})
);
req.end();
};
Hope this helps and feel free to reach out if you encounter any problems.
Hi, @KSimmons👋 Thanks for the interesting question. I'd like to invite some of our community members to the conversation. Hey, @Teun@KimM@LMeert, have you tackled anything similar in your work?