Google-api-nodejs-client: calendar.calendars.insert always results in a Missing Title error

Created on 22 Oct 2018  路  3Comments  路  Source: googleapis/google-api-nodejs-client

Whenever I run the calendar.calendars.insert function, I always get "Error: Missing Title". The docs say that the only required parameter is "summary", which is the title.

I took a look through the source code and I think part of the error is that within calendar.calendars.insert, the requiredParams array of the parameters object is empty, when it should contain summary. Relevant function below, and linked here .

  /**
     * calendar.calendars.insert
     * @desc Creates a secondary calendar.
     * @alias calendar.calendars.insert
     * @memberOf! ()
     *
     * @param {object} params Parameters for request
     * @param {().Calendar} params.resource Request body data
     * @param {object} [options] Optionally override request options, such as `url`, `method`, and `encoding`.
     * @param {callback} callback The callback that handles the response.
     * @return {object} Request object
     */
    insert(params?: Params$Resource$Calendars$Insert, options?: MethodOptions):
        AxiosPromise<Schema$Calendar>;
    insert(
        params: Params$Resource$Calendars$Insert,
        options: MethodOptions|BodyResponseCallback<Schema$Calendar>,
        callback: BodyResponseCallback<Schema$Calendar>): void;
    insert(
        params: Params$Resource$Calendars$Insert,
        callback: BodyResponseCallback<Schema$Calendar>): void;
    insert(callback: BodyResponseCallback<Schema$Calendar>): void;
    insert(
        paramsOrCallback?: Params$Resource$Calendars$Insert|
        BodyResponseCallback<Schema$Calendar>,
        optionsOrCallback?: MethodOptions|BodyResponseCallback<Schema$Calendar>,
        callback?: BodyResponseCallback<Schema$Calendar>):
        void|AxiosPromise<Schema$Calendar> {
      let params = (paramsOrCallback || {}) as Params$Resource$Calendars$Insert;
      let options = (optionsOrCallback || {}) as MethodOptions;

      if (typeof paramsOrCallback === 'function') {
        callback = paramsOrCallback;
        params = {} as Params$Resource$Calendars$Insert;
        options = {};
      }

      if (typeof optionsOrCallback === 'function') {
        callback = optionsOrCallback;
        options = {};
      }

      const rootUrl = options.rootUrl || 'https://www.googleapis.com/';
      const parameters = {
        options: Object.assign(
            {
              url: (rootUrl + '/calendar/v3/calendars')
                       .replace(/([^:]\/)\/+/g, '$1'),
              method: 'POST'
            },
            options),
        params,
        requiredParams: [],
        pathParams: [],
        context: this.getRoot()
      };
      if (callback) {
        createAPIRequest<Schema$Calendar>(parameters, callback);
      } else {
        return createAPIRequest<Schema$Calendar>(parameters);
      }
    }
question

Most helpful comment

I was getting this same error but if you nest it inside resource it works:

calendar.calendars.insert({
  resource: {
    summary: "Calendar Title"
  }
})

All 3 comments

I was getting this same error but if you nest it inside resource it works:

calendar.calendars.insert({
  resource: {
    summary: "Calendar Title"
  }
})

@ACMerriman
The minimum required parameter for calendar.calendars.insert() function is the summary: Title of the calendar. Along with summary you can pass other values attributed to calendar (reference).

To properly pass parameters you have to specify the request body.

The example would be as follows

const res = await calendar.calendars.insert({
  requestBody: {
    summary: "Calendar Title", // required
    timezone: "Europe/Zurich", // optional
    description: "My Calendar" // optional
  }
})

Please confirm whether it worked for you.

@JustinBeckwith I think this could be closed too with https://github.com/googleapis/google-api-nodejs-client/issues/1399#issuecomment-432615221.

Was this page helpful?
0 / 5 - 0 ratings