Hide

Calendars: insert

Requires authorization

Creates a secondary calendar. Try it now or see an example.

Request

HTTP request

POST https://www.googleapis.com/calendar/v3/calendars

Authorization

This request requires authorization with the following scope (read more about authentication and authorization).

Scope
https://www.googleapis.com/auth/calendar

Request body

In the request body, supply a Calendars resource with the following properties:

Property name Value Description Notes
Required Properties
summary string Title of the calendar. writable

Response

If successful, this method returns a Calendars resource in the response body.

Examples

Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).

Java

Uses the Java client library.

import com.google.api.services.calendar.Calendar;

// ...

// Initialize Calendar service with valid OAuth credentials
Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)
    .setApplicationName("applicationName").build();

// Create a new calendar
com.google.api.services.calendar.model.Calendar calendar = new Calendar();
calendar.setSummary("calendarSummary");
calendar.setTimeZone("America/Los_Angeles");

// Insert the new calendar
Calendar createdCalendar = service.calendars().insert(calendar).execute();

System.out.println(createdCalendar.getId());

Python

Uses the Python client library.

calendar = {
    'summary': 'calendarSummary',
    'timeZone': 'America/Los_Angeles'
}

created_calendar = service.calendars().insert(body=calendar).execute()

print created_calendar['id']

PHP

Uses the PHP client library.

$calendar = new Google_Service_Calendar_Calendar();
$calendar->setSummary('calendarSummary');
$calendar->setTimeZone('America/Los_Angeles');

$createdCalendar = $service->calendars->insert($calendar);

echo $createdCalendar->getId();

Ruby

Uses the Ruby client library.

Calendar calendar = new Calendar()
    {
      Summary = "calendarSummary",
      TimeZone = "America/Los_Angeles"
    };

Calendar createdCalendar = service.Calendars.Insert(calendar).Fetch();

Console.WriteLine(createdCalendar.Id);

Try it!

Use the APIs Explorer below to call this method on live data and see the response.

Send feedback about...

Google Calendar API