Search code examples
javascriptreactjsgoogle-apigoogle-oauthgoogle-calendar-api

How can I create a Google Meet link with Google Calendar API?


I am using Google Calendar API to create an event in Google Calendar API. This part is already working, but now I am trying to add a Google Meet link associated to that event, and I can't make it work. This is the code:

const event = {
      'summary': eventName,
      'description': eventDescription,
      'attendees': [
        { 'email': emailFormatado }
      ],
      'start': {
        'dateTime': start.toISOString(),
        'timeZone': Intl.DateTimeFormat().resolvedOptions().timeZone
      },
      'end': {
        'dateTime': end.toISOString(), // Date.toISOString() ->
        'timeZone': Intl.DateTimeFormat().resolvedOptions().timeZone
      },
      'conferenceData': {
        'conferenceDataVersion': 1,
        'createRequest': {
          'requestId': 'sample123',
          'conferenceSolutionKey': { 'type': 'hangoutsMeet' },
        },
      }
    }

    await fetch("https://www.googleapis.com/calendar/v3/calendars/primary/events", {
      method: "POST",
      headers: {
        'Authorization': 'Bearer ' + session.provider_token
      },
      body: JSON.stringify(event)
    }).then((data) => {
      return data.json();
    }).then((data) => {
      console.log(data);
    });

I tried messing with the request and with the order of the parameters, still didn't work. The event created is still missing the Google Meet link


Solution

  • In your script, please use 'conferenceDataVersion': 1 as the query parameter. So, please modify as follows.

    Modified script:

    const event = {
      'summary': eventName,
      'description': eventDescription,
      'attendees': [
        { 'email': emailFormatado }
      ],
      'start': {
        'dateTime': start.toISOString(),
        'timeZone': Intl.DateTimeFormat().resolvedOptions().timeZone
      },
      'end': {
        'dateTime': end.toISOString(), // Date.toISOString() ->
        'timeZone': Intl.DateTimeFormat().resolvedOptions().timeZone
      },
      'conferenceData': {
        'createRequest': {
          'requestId': 'sample123',
          'conferenceSolutionKey': { 'type': 'hangoutsMeet' },
        },
      }
    }
    
    await fetch("https://www.googleapis.com/calendar/v3/calendars/primary/events?conferenceDataVersion=1", {
      method: "POST",
      headers: {
        'Authorization': 'Bearer ' + session.provider_token
      },
      body: JSON.stringify(event)
    }).then((data) => {
      return data.json();
    }).then((data) => {
      console.log(data);
    });
    

    Note:

    • This modification supposes that your access token and the values of variables are valid values. Please be careful about this.

    Reference: