Show
Creates an event. Try it now or see an example. RequestHTTP requestPOST https://www.googleapis.com/calendar/v3/calendars/calendarId/events Parameters
AuthorizationThis request requires authorization with at least one of the following scopes:
For more information, see the authentication and authorization page. Request bodyIn the request body, supply an Events resource with the following properties:
ResponseIf successful, this method returns an Events resource in the response body. ExamplesNote: 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). Uses the Java client library. // Refer to the Java quickstart on how to setup the environment: // https://developers.google.com/calendar/quickstart/java // Change the scope to CalendarScopes.CALENDAR and delete any stored // credentials. Event event = new Event() .setSummary("Google I/O 2015") .setLocation("800 Howard St., San Francisco, CA 94103") .setDescription("A chance to hear more about Google's developer products."); DateTime startDateTime = new DateTime("2015-05-28T09:00:00-07:00"); EventDateTime start = new EventDateTime() .setDateTime(startDateTime) .setTimeZone("America/Los_Angeles"); event.setStart(start); DateTime endDateTime = new DateTime("2015-05-28T17:00:00-07:00"); EventDateTime end = new EventDateTime() .setDateTime(endDateTime) .setTimeZone("America/Los_Angeles"); event.setEnd(end); String[] recurrence = new String[] {"RRULE:FREQ=DAILY;COUNT=2"}; event.setRecurrence(Arrays.asList(recurrence)); EventAttendee[] attendees = new EventAttendee[] { new EventAttendee().setEmail(""), new EventAttendee().setEmail(""), }; event.setAttendees(Arrays.asList(attendees)); EventReminder[] reminderOverrides = new EventReminder[] { new EventReminder().setMethod("email").setMinutes(24 * 60), new EventReminder().setMethod("popup").setMinutes(10), }; Event.Reminders reminders = new Event.Reminders() .setUseDefault(false) .setOverrides(Arrays.asList(reminderOverrides)); event.setReminders(reminders); String calendarId = "primary"; event = service.events().insert(calendarId, event).execute(); System.out.printf("Event created: %s\n", event.getHtmlLink()); PythonUses the Python client library. # Refer to the Python quickstart on how to setup the environment: # https://developers.google.com/calendar/quickstart/python # Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any # stored credentials. event = { 'summary': 'Google I/O 2015', 'location': '800 Howard St., San Francisco, CA 94103', 'description': 'A chance to hear more about Google\'s developer products.', 'start': { 'dateTime': '2015-05-28T09:00:00-07:00', 'timeZone': 'America/Los_Angeles', }, 'end': { 'dateTime': '2015-05-28T17:00:00-07:00', 'timeZone': 'America/Los_Angeles', }, 'recurrence': [ 'RRULE:FREQ=DAILY;COUNT=2' ], 'attendees': [ {'email': ''}, {'email': ''}, ], 'reminders': { 'useDefault': False, 'overrides': [ {'method': 'email', 'minutes': 24 * 60}, {'method': 'popup', 'minutes': 10}, ], }, } event = service.events().insert(calendarId='primary', body=event).execute() print 'Event created: %s' % (event.get('htmlLink')) PHPUses the PHP client library. // Refer to the PHP quickstart on how to setup the environment: // https://developers.google.com/calendar/quickstart/php // Change the scope to Google_Service_Calendar::CALENDAR and delete any stored // credentials. $event = new Google_Service_Calendar_Event(array( 'summary' => 'Google I/O 2015', 'location' => '800 Howard St., San Francisco, CA 94103', 'description' => 'A chance to hear more about Google\'s developer products.', 'start' => array( 'dateTime' => '2015-05-28T09:00:00-07:00', 'timeZone' => 'America/Los_Angeles', ), 'end' => array( 'dateTime' => '2015-05-28T17:00:00-07:00', 'timeZone' => 'America/Los_Angeles', ), 'recurrence' => array( 'RRULE:FREQ=DAILY;COUNT=2' ), 'attendees' => array( array('email' => ''), array('email' => ''), ), 'reminders' => array( 'useDefault' => FALSE, 'overrides' => array( array('method' => 'email', 'minutes' => 24 * 60), array('method' => 'popup', 'minutes' => 10), ), ), )); $calendarId = 'primary'; $event = $service->events->insert($calendarId, $event); printf('Event created: %s\n', $event->htmlLink); RubyUses the Ruby client library. event = Google::Apis::CalendarV3::Event.new( summary: 'Google I/O 2015', location: '800 Howard St., San Francisco, CA 94103', description: 'A chance to hear more about Google\'s developer products.', start: Google::Apis::CalendarV3::EventDateTime.new( date_time: '2015-05-28T09:00:00-07:00', time_zone: 'America/Los_Angeles' ), end: Google::Apis::CalendarV3::EventDateTime.new( date_time: '2015-05-28T17:00:00-07:00', time_zone: 'America/Los_Angeles' ), recurrence: [ 'RRULE:FREQ=DAILY;COUNT=2' ], attendees: [ Google::Apis::CalendarV3::EventAttendee.new( email: '' ), Google::Apis::CalendarV3::EventAttendee.new( email: '' ) ], reminders: Google::Apis::CalendarV3::Event::Reminders.new( use_default: false, overrides: [ Google::Apis::CalendarV3::EventReminder.new( reminder_method: 'email', minutes: 24 * 60 ), Google::Apis::CalendarV3::EventReminder.new( reminder_method: 'popup', minutes: 10 ) ] ) ) result = client.insert_event('primary', event) puts "Event created: #{result.html_link}" .NETUses the .NET client library. // Refer to the .NET quickstart on how to setup the environment: // https://developers.google.com/calendar/quickstart/dotnet // Change the scope to CalendarService.Scope.Calendar and delete any stored // credentials. Event newEvent = new Event() { Summary = "Google I/O 2015", Location = "800 Howard St., San Francisco, CA 94103", Description = "A chance to hear more about Google's developer products.", Start = new EventDateTime() { DateTime = DateTime.Parse("2015-05-28T09:00:00-07:00"), TimeZone = "America/Los_Angeles", }, End = new EventDateTime() { DateTime = DateTime.Parse("2015-05-28T17:00:00-07:00"), TimeZone = "America/Los_Angeles", }, Recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=2" }, Attendees = new EventAttendee[] { new EventAttendee() { Email = "" }, new EventAttendee() { Email = "" }, }, Reminders = new Event.RemindersData() { UseDefault = false, Overrides = new EventReminder[] { new EventReminder() { Method = "email", Minutes = 24 * 60 }, new EventReminder() { Method = "sms", Minutes = 10 }, } } }; String calendarId = "primary"; EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId); Event createdEvent = request.Execute(); Console.WriteLine("Event created: {0}", createdEvent.HtmlLink); GoUses the Go client library. // Refer to the Go quickstart on how to setup the environment: // https://developers.google.com/calendar/quickstart/go // Change the scope to calendar.CalendarScope and delete any stored credentials. event := &calendar.Event{ Summary: "Google I/O 2015", Location: "800 Howard St., San Francisco, CA 94103", Description: "A chance to hear more about Google's developer products.", Start: &calendar.EventDateTime{ DateTime: "2015-05-28T09:00:00-07:00", TimeZone: "America/Los_Angeles", }, End: &calendar.EventDateTime{ DateTime: "2015-05-28T17:00:00-07:00", TimeZone: "America/Los_Angeles", }, Recurrence: []string{"RRULE:FREQ=DAILY;COUNT=2"}, Attendees: []*calendar.EventAttendee{ &calendar.EventAttendee{Email:""}, &calendar.EventAttendee{Email:""}, }, } calendarId := "primary" event, err = srv.Events.Insert(calendarId, event).Do() if err != nil { log.Fatalf("Unable to create event. %v\n", err) } fmt.Printf("Event created: %s\n", event.HtmlLink) JavaScriptUses the JavaScript client library. // Refer to the JavaScript quickstart on how to setup the environment: // https://developers.google.com/calendar/quickstart/js // Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any // stored credentials. var event = { 'summary': 'Google I/O 2015', 'location': '800 Howard St., San Francisco, CA 94103', 'description': 'A chance to hear more about Google\'s developer products.', 'start': { 'dateTime': '2015-05-28T09:00:00-07:00', 'timeZone': 'America/Los_Angeles' }, 'end': { 'dateTime': '2015-05-28T17:00:00-07:00', 'timeZone': 'America/Los_Angeles' }, 'recurrence': [ 'RRULE:FREQ=DAILY;COUNT=2' ], 'attendees': [ {'email': ''}, {'email': ''} ], 'reminders': { 'useDefault': false, 'overrides': [ {'method': 'email', 'minutes': 24 * 60}, {'method': 'popup', 'minutes': 10} ] } }; var request = gapi.client.calendar.events.insert({ 'calendarId': 'primary', 'resource': event }); request.execute(function(event) { appendPre('Event created: ' + event.htmlLink); }); Node.jsUses the Node.js client library. // Refer to the Node.js quickstart on how to setup the environment: // https://developers.google.com/calendar/quickstart/node // Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any // stored credentials. var event = { 'summary': 'Google I/O 2015', 'location': '800 Howard St., San Francisco, CA 94103', 'description': 'A chance to hear more about Google\'s developer products.', 'start': { 'dateTime': '2015-05-28T09:00:00-07:00', 'timeZone': 'America/Los_Angeles', }, 'end': { 'dateTime': '2015-05-28T17:00:00-07:00', 'timeZone': 'America/Los_Angeles', }, 'recurrence': [ 'RRULE:FREQ=DAILY;COUNT=2' ], 'attendees': [ {'email': ''}, {'email': ''}, ], 'reminders': { 'useDefault': false, 'overrides': [ {'method': 'email', 'minutes': 24 * 60}, {'method': 'popup', 'minutes': 10}, ], }, }; calendar.events.insert({ auth: auth, calendarId: 'primary', resource: event, }, function(err, event) { if (err) { console.log('There was an error contacting the Calendar service: ' + err); return; } console.log('Event created: %s', event.htmlLink); }); Try it!Use the APIs Explorer below to call this method on live data and see the response. Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Last updated 2022-04-20 UTC. [{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }] How do I add an event to someone else's Google Calendar?To do so, click on the calendar that is currently selected, to see a drop down of all your calendar options. Then, click on the shared calendar you want to add your event to. If you don't see the calendar there, you'll need to request editing access, or create your own shared calendar.
Can you add events from one Google Calendar to another?To move an event from one calendar to another, you must be the organizer of a Google Calendar event. You must also have edit access to the calendar you move the event to. When you move an event, you add the event's organizers to the new calendar and remove organizers from the old calendar.
|