APIs & Integrations

KSimmons
Participant

Finding the next meeting

SOLVE

Is there a good way to search or retrieve the start time of the NEXT meeting for a company or contact?   

 

I need the start time (date plus time in a string or text field) to include in emails and documents.

 

Seems like there are two ways to approch pulling the start date of a meeting for a particular company.

1. Get all of the meetings associated with the company and then filter for the soonest upcoming date.  Return next date

2.  Search for meetings that occur in the next 14 days.  Return the meeting date that the search API returns

 

Are either of these two options better?  Or is there a more straightforward workflow to print the meeting start time to a property?  

0 Upvotes
1 Accepted solution
KimM
Solution
Top Contributor

Finding the next meeting

SOLVE

Hi @KSimmons ,

 

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.

 

Cheers,

Kim

View solution in original post

4 Replies 4
KimM
Solution
Top Contributor

Finding the next meeting

SOLVE

Hi @KSimmons ,

 

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.

 

Cheers,

Kim

KSimmons
Participant

Finding the next meeting

SOLVE

Thanks.  That works!

0 Upvotes
KimM
Top Contributor

Finding the next meeting

SOLVE

Great to hear @KSimmons. Happy to help.

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

Finding the next meeting

SOLVE

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?

 

Thanks for taking a look! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes