question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

google.calendar.events.insert fails when adding conferenceData

See original GitHub issue

Environment details

  • OS: firebase-tools@10.9.2
  • Node.js version: v16.15.1
  • npm version: 8.11.0
  • googleapis version: googleapis@107.0.0

Steps to reproduce

Steps to reproduce Create google event using google.calendar.events.insert Returned error: Invalid conference type value API is authenticated as google service account and domain-wide delegation is done from google workspace admin. Using Google Workspace Business Starter account. The service account works with no issue, and the meeting is created whenconferenceDataVersion: 1 is not set

here is the snippet:

const SCOPES = ["https://www.googleapis.com/auth/calendar"];

const jwtClient = new google.auth.JWT(
    GOOGLE_CLIENT_EMAIL,
    null,
    GOOGLE_PRIVATE_KEY,
    SCOPES,
);

const calendar = google.calendar({
  version: "v3",
  project: GOOGLE_PROJECT_NUMBER,
  auth: jwtClient,
});

const auth = new google.auth.GoogleAuth({
  keyFile: "./keys.json",
  scopes: SCOPES,
});

 // Add event to calendar and get the link
  const calendarEvent = {
    summary: "Test",
    description: "Test.",
    start: {
      dateTime: data.booking.startDate,
      timeZone: "America/Los_Angeles", // TODO figure out timezones
    },
    end: {
      dateTime: data.booking.endDate,
      timeZone: "America/Los_Angeles", // TODO figure out timezones
    },
    conferenceData: {
      createRequest: {
        requestId: "sample123",
        conferenceSolutionKey: {type: "hangoutsMeet"},
      },
    },
    attendees: [],
    reminders: {
      useDefault: false,
      overrides: [
        {method: "email", minutes: 24 * 60},
        {method: "popup", minutes: 10},
      ],
    },
  };

  addCalendarEvent(calendarEvent);

const addCalendarEvent = async (calendarEvent) => {
  try {
    auth.getClient().then(async (auth) => {
      console.log("addCalendarEvent: " +GOOGLE_CALENDAR_ID);
      try {
        calendar.events.insert(
            {
              auth: auth,
              calendarId: GOOGLE_CALENDAR_ID,
              resource: calendarEvent,
              conferenceDataVersion: 1, // Doesnt work
            },
            function(error, response) {
              console.log(JSON.stringify(response));
              if (error) {
                console.log("Something went wrong:" + JSON.stringify(error)); // If there is an error, log it to the console
                return;
              }
              console.log("Event created successfully.");
              console.log("Event details: ", JSON.stringify(response.data)); // Log the event details
            },
        );
      } catch (err) {
        console.log("Error in insert: ", JSON.stringify(err));
      }
    });
  } catch (err) {
    console.log("Error in auth: ", JSON.stringify(err));
  }
};

Output when using hangoutsMeet ,eventHangout or eventNamedHangout: Something went wrong:{“response”:{“config”:{“project”:“1082487788583”,“url”:“https://www.googleapis.com/calendar/v3/calendars/robert%40hustleforge.com/events?conferenceDataVersion=1",“method”:“POST”,“userAgentDirectives”:[{“product”:“google-api-nodejs-client”,“version”:“6.0.1”,“comment”:“gzip”}],“data”:{“summary”:“test”:“test.”,“start”:{“dateTime”:“2022-09-02T18:00:00.000Z”,“timeZone”:“America/Los_Angeles”},“end”:{“dateTime”:“2022-09-02T19:00:00.000Z”,“timeZone”:“America/Los_Angeles”},“conferenceData”:{“createRequest”:{“requestId”:“sample123”,“conferenceSolutionKey”:{“type”:“eventHangout”}}},“attendees”:[],“reminders”:{“useDefault”:false,“overrides”:[{“method”:“email”,“minutes”:1440},{“method”:“popup”,“minutes”:10}]}},“headers”:{“x-goog-api-client”:"gdcl/6.0.1 gl-node/14.20.0 auth/8.3.0”,“Accept-Encoding”:“gzip”,“User-Agent”:“google-api-nodejs-client/6.0.1 (gzip)”,“Authorization”:“XXX”,“Content-Type”:“application/json”,“Accept”:“application/json”},“params”:{“conferenceDataVersion”:1},“retry”:true,“body”:“{"summary":"test","description":"test.","start":{"dateTime":"2022-09-02T18:00:00.000Z","timeZone":"America/Los_Angeles"},"end":{"dateTime":"2022-09-02T19:00:00.000Z","timeZone":"America/Los_Angeles"},"conferenceData":{"createRequest":{"requestId":"sample123","conferenceSolutionKey":{"type":"eventHangout"}}},"attendees":[],"reminders":{"useDefault":false,"overrides":[{"method":"email","minutes":1440},{"method":"popup","minutes":10}]}}”,“responseType”:“json”,“retryConfig”:{“currentRetryAttempt”:0,“retry”:3,“httpMethodsToRetry”:[“GET”,“HEAD”,“PUT”,“OPTIONS”,“DELETE”],“noResponseRetries”:2,“statusCodesToRetry”:[[100,199],[429,429],[500,599]]}},“data”:{“error”:{“errors”:[{“domain”:“global”,“reason”:“invalid”,“message”:“Invalid conference type value.”}],“code”:400,“message”:“Invalid conference type value.”}},“headers”:{“alt-svc”:“h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"”,“cache-control”:“no-cache, no-store, max-age=0, must-revalidate”,“connection”:“close”,“content-encoding”:“gzip”,“content-type”:“application/json; charset=UTF-8”,“date”:“Wed, 24 Aug 2022 04:57:17 GMT”,“expires”:“Mon, 01 Jan 1990 00:00:00 GMT”,“pragma”:“no-cache”,“server”:“ESF”,“transfer-encoding”:“chunked”,“vary”:“Origin, X-Origin, Referer”,“x-content-type-options”:“nosniff”,“x-frame-options”:“SAMEORIGIN”,“x-xss-protection”:“0”},“status”:400,“statusText”:“Bad Request”,“request”:{“responseURL”:“https://www.googleapis.com/calendar/v3/calendars/robert%40hustleforge.com/events?conferenceDataVersion=1"}},“config”:{“project”:“1082487788583”,“url”:“https://www.googleapis.com/calendar/v3/calendars/robert%40hustleforge.com/events?conferenceDataVersion=1”,“method”:“POST”,“userAgentDirectives”:[{“product”:“google-api-nodejs-client”,“version”:“6.0.1”,“comment”:“gzip”}],“data”:{“summary”:“test”,“description”:“test.”,“start”:{“dateTime”:“2022-09-02T18:00:00.000Z”,“timeZone”:“America/Los_Angeles”},“end”:{“dateTime”:“2022-09-02T19:00:00.000Z”,“timeZone”:“America/Los_Angeles”},“conferenceData”:{“createRequest”:{“requestId”:“sample123”,“conferenceSolutionKey”:{“type”:“eventHangout”}}},“attendees”:[],“reminders”:{“useDefault”:false,“overrides”:[{“method”:“email”,“minutes”:1440},{“method”:“popup”,“minutes”:10}]}},“headers”:{“x-goog-api-client”:"gdcl/6.0.1 gl-node/14.20.0 auth/8.3.0”,“Accept-Encoding”:“gzip”,“User-Agent”:“google-api-nodejs-client/6.0.1 (gzip)”,“Authorization”:“XXX”,“Content-Type”:“application/json”,“Accept”:“application/json”},“params”:{“conferenceDataVersion”:1},“retry”:true,“body”:“{"summary":"test","description":"test","start":{"dateTime":"2022-09-02T18:00:00.000Z","timeZone":"America/Los_Angeles"},"end":{"dateTime":"2022-09-02T19:00:00.000Z","timeZone":"America/Los_Angeles"},"conferenceData":{"createRequest":{"requestId":"sample123","conferenceSolutionKey":{"type":"eventHangout"}}},"attendees":[],"reminders":{"useDefault":false,"overrides":[{"method":"email","minutes":1440},{"method":"popup","minutes":10}]}}”,“responseType”:“json”,“retryConfig”:{“currentRetryAttempt”:0,“retry”:3,“httpMethodsToRetry”:[“GET”,“HEAD”,“PUT”,“OPTIONS”,“DELETE”],“noResponseRetries”:2,“statusCodesToRetry”:[[100,199],[429,429],[500,599]]}},“code”:400,“errors”:[{“domain”:“global”,“reason”:“invalid”,“message”:“Invalid conference type value.”}]}

Thanks!

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
rlarmorecommented, Nov 16, 2022

Hey! Thanks for the suggestions. Good to know you have it working, means it’s possible. I follow your steps to see if I’m missing something.

0reactions
cAtamancommented, Nov 27, 2022

Hey @herbola thanks for the suggestion. This didn’t work for me though and the service account kept getting an error while trying to impersonate the admin. Even after supplying all available permissions and roles.

I just abandoned service accounts entirely and instead authenticated directly with an admin account.

I first created an OAuth application on Google Cloud, then used that to Authenticate admin users from which I’d get a refresh_token. This refresh token would be used internally in the app to generate new access tokens when needed.

A refresh token would expire in about if not used for 6 months, at which point the admin user would have to generate a new one. This would not be a problem for my use-case as the feature which I need the Events API for is only called by admin users.

  • Getting credentials

from google_auth_oauthlib.flow import Flow


class CalendarHelperService:
    @staticmethod
    def get_auth_url(request):
        flow = Flow.from_client_secrets_file(
            client_secrets_file=settings.GOOGLE_OAUTH_CLIENT_FILENAME,
            scopes=settings.AUTH_SCOPES,
        )
        flow.redirect_uri = reverse("some-internal-url", request=request)
        url, state = flow.authorization_url()
        return url, state

    @staticmethod
    def get_tokens(request):
        params = request.query_params.dict()
        flow = Flow.from_client_secrets_file(
            client_secrets_file=settings.GOOGLE_OAUTH_CLIENT_FILENAME,
            scopes=settings.AUTH_SCOPES,
        )
        flow.redirect_uri = reverse("some-internal-url", request=request)
        token_dict = flow.fetch_token(code=params.get("code"))

        # write credentials to file
        oauth_creds = json.load(open(settings.GOOGLE_OAUTH_CLIENT_FILENAME))
        _secret = {**oauth_creds.get("web"), **token_dict, "token": token_dict}
        json.dump(
            _secret, open(settings.GOOGLE_CALENDAR_SECRETS_FILENAME, "w"), indent=4
        )

I exposed the two methods of this service on the server accessible only by admin users. The admin user just has to call the first method and then follow throught with Google’s authentication. When this completes, the second method would be called to save the credentials (auth_token, refresh_token, etc) on the server.

  • Using the credentials

from google.oauth2.credentials import Credentials


creds = Credentials.from_authorized_user_file(
    settings.GOOGLE_CALENDAR_SECRETS_FILENAME, scopes=settings.AUTH_SCOPES
)
  • Where

    •  settings.AUTH_SCOPES = [
           "https://www.googleapis.com/auth/cloud-platform",
           "https://www.googleapis.com/auth/calendar",
           "https://www.googleapis.com/auth/calendar.events",
       ]
      
    •  settings.GOOGLE_CALENDAR_SECRETS_FILENAME = "/path/to/secrets/file"  # file that stores live auth credentials
       settings.GOOGLE_OAUTH_CLIENT_FILENAME = "/path/to/OAuth/App/json_file"  # JSON file of the OAuth application in use
      
Read more comments on GitHub >

github_iconTop Results From Across the Web

API call to calendar.events.insert failed with error
I am trying to build third party conferencing google calendar add-on. For creating conference data, I am passing below object.
Read more >
Events: insert | Google Calendar
Property name Value Notes end nested object start nested object anyoneCanAddSelf boolean writable
Read more >
No conference data is received when adding an event via ...
We have been using Google Calendar insert API as calendarService.events().insert(CALENDAR_ID, event).execute(); and it was very successful until 09/01 PST when ...
Read more >
Import events to Google Calendar - Computer
When you import an event, guests and conference data for that event are not imported. ... Choose which calendar to add the imported...
Read more >
Time Range Error - Google Groups
I am creating calendar events using the Calendar API v3 (.NET). I can use the events QuickAdd method but receive an errror when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found