Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new google meet using google calendar api

I need implement a javascript project that creates a new google meet according to the user signed in and adds the event to the calendar and gets the url of the google meet. How can i create a new google meet using Google Calendar API in JS.

like image 616
Vishnu Darshan Avatar asked Oct 26 '20 15:10

Vishnu Darshan


3 Answers

If you aren't using the node library, the request with axios is below. I did not realize from the answer above conferenceDataVersion is a query param.

let event = {
    summary: "some text",
    location: "some text",
    description: "some text",
    start: {
      dateTime: start,
      timeZone: timeZone,
    },
    end: {
      dateTime: end,
      timeZone: timeZone,
    },
    recurrence: [],
    attendees: [
      { email: '[email protected]' }, 

    ],
    reminders: {
      useDefault: true,
    },
    conferenceData: {
      createRequest: {
        conferenceSolutionKey: {
          type: 'hangoutsMeet',
        },
        requestId: 'somerequestid',
      },
    },
  };
  
const createEventRequest = await axios({
    url: `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events?conferenceDataVersion=1`,
    method: 'POST',
    headers: {
      Authorization: `Bearer ${accessToken}`,
    },
    data: event,
  });
like image 150
Brit Gwaltney Avatar answered Oct 31 '22 18:10

Brit Gwaltney


Answer:

You need to use the conferenceData.createRequest parameter of the Events resource when creating a Calendar.Events: insert request to add a Meet link to a Calendar Event.

More Information:

As per the documention for Events: insert and the Event resource reperesentation:

conferenceDataVersion: integer

Version number of conference data supported by the API client. Version 0 assumes no conference data support and ignores conference data in the event's body. Version 1 enables support for copying of ConferenceData as well as for creating new conferences using the createRequest field of conferenceData. The default is 0. Acceptable values are 0 to 1, inclusive.


conferenceData.createRequest: nested object

A request to generate a new conference and attach it to the event. The data is generated asynchronously. To see whether the data is present check the status field.

Either conferenceSolution and at least one entryPoint, or createRequest is required.


conferenceData.createRequest.conferenceSolutionKey.type: string

The conference solution type.

If a client encounters an unfamiliar or empty type, it should still be able to display the entry points. However, it should disallow modifications.

The possible values are:

  • "eventHangout" for Hangouts for consumers (http://hangouts.google.com)
  • "eventNamedHangout" for classic Hangouts for G Suite users (http://hangouts.google.com)
  • "hangoutsMeet" for Google Meet (http://meet.google.com)
  • "addOn" for 3P conference providers

conferenceData.createRequest.requestId: string

The client-generated unique ID for this request. Clients should regenerate this ID for every new request. If an ID provided is the same as for the previous request, the request is ignored.

With this information we can generate a Calendar Event creation request with a Meet link as the conference solution.

Example Request:

gapi.client.calendar.events.insert({
  "calendarId": "primary",
  "conferenceDataVersion": 1,
  "resource": {
    "end": {
      "date": "2020-10-24"
    },
    "start": {
      "date": "2020-10-23"
    },
    "conferenceData": {
      "createRequest": {
        "conferenceSolutionKey": {
          "type": "hangoutsMeet"
        },
        "requestId": "some-random-string"
      }
    },
    "summary": "titles are cool"
  }
});

NB: In order for a Meet link to be generated, you must set conferenceData.createRequest.requestId to any random string. For each new meet link you wish to create, you must use a different string in the request.

References:

  • Events: insert | Calendar API | Google Developers
  • Events | Calendar API | Google Developers
like image 26
I hope this is helpful to you Avatar answered Oct 31 '22 17:10

I hope this is helpful to you


Extending @Brit's comment in googleapis npm package the way it should be executed will be

let response = await calendar.events.insert({
    auth: auth,
        calendarId: calendarId,
        resource: event,
        conferenceDataVersion: 1
    });

with event as

let event = {
    'summary': `Appointment.`,
    'description': `Description`,
    'start': {
        'dateTime': dateTime['start'],
        'timeZone': 'Asia/Kolkata'
    },
    'end': {
        'dateTime': dateTime['end'],
        'timeZone': 'Asia/Kolkata'
    },
    'attendees': [
        {'email': '[email protected]'},
    ],
    'reminders': {
        'useDefault': false,
        'overrides': [
          {'method': 'email', 'minutes': 24 * 60},
          {'method': 'popup', 'minutes': 10},
        ],
    },
    "conferenceData": {
        "createRequest": {
            "conferenceSolutionKey": {
                "type": "hangoutsMeet"
            },
            "requestId": "JksKJJSK1KJSK"
        }
    },
    
};
like image 33
Madhuri Lakkireddy Avatar answered Oct 31 '22 18:10

Madhuri Lakkireddy