How to add an event with javascript library - calendar v3

12,000 views
Skip to first unread message

Rubén Sánchez

unread,
Dec 16, 2011, 9:02:05 AM12/16/11
to google-ca...@googlegroups.com
Hi guys, I just discovered the javascript libraries and even if this is still in alpha, it looks promising.
However, I have a question, in the example, I get a list of events. So:

- How can I add an event? What is the structure of this call?
- Where can I see the structure of the other methods for updating, deleting, adding resources in the calendar api?
 
function makeApiCall() {
 gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.events.list({
 'calendarId': 'primary'
});
 
request.execute(function(resp) {
 for (var i = 0; i < resp.items.length; i++) {
var li = document.createElement('li');
li.appendChild(document.createTextNode(resp.items[i].summary));
document.getElementById('events').appendChild(li);
 }
});
 });
}


Thanks in advance.

Dan Holevoet

unread,
Dec 16, 2011, 2:58:16 PM12/16/11
to google-ca...@googlegroups.com
Hi Ruben,

The functions in this library map very closely to the structure of other libraries, or the API calls you'd make in the APIs Console. So, for example to insert a Calendar event the method to call would be gapi.client.calendar.events.insert.

However, the documentation site for the client library seems to be lacking, so I'll talk to the team and try and get some good examples published.

Thanks,
Dan

2011/12/16 Rubén Sánchez <ruben...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Calendar API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-calendar-api/-/A51OlG1tUr8J.
To post to this group, send email to google-ca...@googlegroups.com.
To unsubscribe from this group, send email to google-calendar...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-calendar-api?hl=en.



--
Dan Holevoet
Google Developer Relations

Dan Holevoet

unread,
Dec 16, 2011, 3:33:46 PM12/16/11
to google-ca...@googlegroups.com
Hi again,

In the interim, here is an example of inserting a Calendar event. This code assumes you have already configured and loaded v3 using the published examples:

var resource = {
  "summary": "Appointment",
  "location": "Somewhere",
  "start": {
    "dateTime": "2011-12-16T10:00:00.000-07:00"
  },
  "end": {
    "dateTime": "2011-12-16T10:25:00.000-07:00"
    }
  };
var request = gapi.client.calendar.events.insert({
  'calendarId': 'primary',
  'resource': resource
});
request.execute(function(resp) {
  console.log(resp);
});

The parameters passed into the call are the URL parameters (in the same manner as in get or list). The only difference is that you also pass in a resource parameter, which contains the resource you are interested in creating or updating. Delete calls will not not need a resource, and should behave similar to a get.

Thanks,
Dan

Bob Myers

unread,
Dec 20, 2011, 12:03:45 PM12/20/11
to google-ca...@googlegroups.com
Is there any plan to document the use of the resource: parameter, or provide a single solitary example of making an API call which involves a request body, so that poor slobs like me don't have to spend two days Googling and experimenting and decoding network packets to figure it out before we finally chance upon the one single place in the world where it's described--the post from Dan?

Dan Holevoet

unread,
Dec 20, 2011, 2:38:15 PM12/20/11
to google-ca...@googlegroups.com
Hi,

As I said in the first reply, we're going to get the client library documentation updated with some examples. I provided one example in this thread as an interim solution so people wouldn't have to wait. At some point, I'd also like to give the same treatment we have for Java/Python/PHP/etc in the Using the API guide, to JS, but that will definitely not happen in 2011.

Thanks,
Dan

On Tue, Dec 20, 2011 at 9:03 AM, Bob Myers <bobm...@gmail.com> wrote:
Is there any plan to document the use of the resource: parameter, or provide a single solitary example of making an API call which involves a request body, so that poor slobs like me don't have to spend two days Googling and experimenting and decoding network packets to figure it out before we finally chance upon the one single place in the world where it's described--the post from Dan?

--
You received this message because you are subscribed to the Google Groups "Google Calendar API" group.

To post to this group, send email to google-ca...@googlegroups.com.
To unsubscribe from this group, send email to google-calendar...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-calendar-api?hl=en.

Clement Clarke

unread,
Apr 12, 2012, 2:26:07 AM4/12/12
to google-ca...@googlegroups.com

Clement Clarke

unread,
Apr 12, 2012, 2:30:37 AM4/12/12
to google-ca...@googlegroups.com
Hi Dan,

Can this code be run in a Google Spreadsheet or in Sites?

Also, is there a full example somewhere?

Many thanks
Dan


2011/12/16 Rubén Sánchez <ruben...@gmail.com>
To post to this group, send email to google-calendar-api@googlegroups.com.
To unsubscribe from this group, send email to google-calendar-api+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-calendar-api?hl=en.
--
Dan Holevoet
Google Developer Relations




--
Dan Holevoet
Google Developer Relations

Dan


2011/12/16 Rubén Sánchez <ruben...@gmail.com>
To post to this group, send email to google-calendar-api@googlegroups.com.
To unsubscribe from this group, send email to google-calendar-api+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-calendar-api?hl=en.
--
Dan Holevoet
Google Developer Relations

Swapnil Rathod

unread,
May 4, 2012, 3:39:11 AM5/4/12
to google-ca...@googlegroups.com
Hey Dan,

Please provide some example for update and delete eagerly waiting for your reply... 2012 now


On Wednesday, December 21, 2011 1:08:15 AM UTC+5:30, Dan Holevoet wrote:
Hi,

As I said in the first reply, we're going to get the client library documentation updated with some examples. I provided one example in this thread as an interim solution so people wouldn't have to wait. At some point, I'd also like to give the same treatment we have for Java/Python/PHP/etc in the Using the API guide, to JS, but that will definitely not happen in 2011.

Thanks,
Dan

On Tue, Dec 20, 2011 at 9:03 AM, Bob Myers <bobm...@gmail.com> wrote:
Is there any plan to document the use of the resource: parameter, or provide a single solitary example of making an API call which involves a request body, so that poor slobs like me don't have to spend two days Googling and experimenting and decoding network packets to figure it out before we finally chance upon the one single place in the world where it's described--the post from Dan?

--
You received this message because you are subscribed to the Google Groups "Google Calendar API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-calendar-api/-/8CfGOZbSI-sJ.

To post to this group, send email to google-calendar-api@googlegroups.com.
To unsubscribe from this group, send email to google-calendar-api+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-calendar-api?hl=en.

stoney

unread,
Jun 18, 2012, 10:03:03 AM6/18/12
to google-ca...@googlegroups.com
I've been using the javascript library for listing, inserting and deleting events for a few weeks now. For newcomers looking for some examples, I'll post a few tonight. They are just basic examples but maybe it'll be enough to get someone started.

stoney

unread,
Jun 18, 2012, 11:26:26 PM6/18/12
to google-ca...@googlegroups.com
A few very basic examples:

 // FUNCTION TO DELETE EVENT
   function deleteEvent(calendarID,eventID) {
     gapi.client.load('calendar', 'v3', function() {  
       var request = gapi.client.calendar.events.delete({
         'calendarId': calendarID,
         'eventId': eventID
       });
     request.execute(function(resp) {
if (typeof resp === 'undefined') {
alert("Event was successfully removed from the calendar!");
}
else{
alert('An error occurred, please try again later.')
}
     });
     });
   } 
   // END DELETEEVENT FUNCTION

 // FUNCTION TO INSERT EVENT
   function insertEvent(calendar) {
    var resource = {
        "summary":"My Summary",
        "location": "My Location",
"description": "My Description",
        "start": {
          "date": "2012/06/18"  //if not an all day event, "date" should be "dateTime" with a dateTime value formatted according to RFC 3339
        },
        "end": {
          "date": "2012/06/18"  //if not an all day event, "date" should be "dateTime" with a dateTime value formatted according to RFC 3339
        }
      };
     gapi.client.load('calendar', 'v3', function() {  
       var request = gapi.client.calendar.events.insert({
         'calendarId': calendar,
 'resource': resource
       });
     request.execute(function(resp) {
       console.log(resp);
  if (resp.id){
  alert("Event was successfully added to the calendar!");
  }
  else{
  alert("An error occurred. Please try again later.")
  }
       
     });
     });
   } 
   // END INSERTEVENT FUNCTION

  // LIST AVAILABLE CALENDARS THAT HAVE WRITE ACCESS
     function listWritableCalendars() {
 gapi.client.load('calendar', 'v3', function() {
  var request = gapi.client.calendar.calendarList.list({
                  'minAccessRole': 'writer'
                  });
request.execute(function(resp) {
});
 });
}
 // END LIST CALENDARS FUNCTION

// QUERY EXISTING EVENTS FUNCTION
      function checkExists(calID){
gapi.client.load('calendar', 'v3', function() {  
          var request = gapi.client.calendar.events.list({
  'calendarId': calID,
                 'q': "My query string" //set the query string variable
          });
request.execute(function(resp) {
console.log(resp);
  if (resp.items){
for (var i = 0; i < resp.items.length; i++) {
//set event variables and list matching events
}
  }
  else{
alert("No matching events!");
  }
         });
});
       }
// END QUERY EVENTS FUNCTION 

Ernst schoen-rene

unread,
Oct 16, 2012, 6:24:34 PM10/16/12
to google-ca...@googlegroups.com
still no documentation for javascript?  A google search for "google calendar api javascript" brings me to V1, which doesn't work.  Cmon guys, write some JS documentation!

jaffar....@rolustech.com

unread,
Jan 29, 2013, 10:36:26 AM1/29/13
to google-ca...@googlegroups.com
hi, 
i having issues with special characters like & . if & is in descriptin of an event to be added or updated i am getting invalid value error
else its working fine . i am using same code for insert and update as described here in conversation
please help me 

thanks,
Jaffar

Jean Chevallier

unread,
Nov 13, 2013, 10:56:44 AM11/13/13
to google-ca...@googlegroups.com
Hi,

I try to delete an event (no problem to create) but I have the console message : 

Object
  1. code404
  2. dataArray[1]
  3. errorObject
  4. message"Not Found"
  5. __proto__Object

The calendar and the event exists...

Same problem with "API Explorer" message
404 Not Found
- Hide headers -
cache-control:  private, max-age=0
content-encoding:  gzip
content-length:  120
content-type:  application/json; charset=UTF-8
date:  Wed, 13 Nov 2013 15:46:59 GMT
expires:  Wed, 13 Nov 2013 15:46:59 GMT
server:  GSE
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
Message has been deleted

Jeremy Berven

unread,
Jul 28, 2014, 4:48:13 PM7/28/14
to google-ca...@googlegroups.com
The documentation on the Google Developers Console still shows the original example from Ruben's post. It took a couple of days for me to find this example for it to be of any use...2.5 years later
Dan


2011/12/16 Rubén Sánchez <ruben...@gmail.com>
To unsubscribe from this group, send email to google-calendar-api+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-calendar-api?hl=en.
--
Dan Holevoet
Google Developer Relations

Message has been deleted

Matt McCallum

unread,
Dec 15, 2017, 12:58:30 AM12/15/17
to Google Calendar API
It's now 2017 and there is still no documentation.  Gotta love it.
Reply all
Reply to author
Forward
0 new messages