0

I am trying to add an event to a particular calendar in my calendar list using the recommended Javascript code provided by the Google Calendar API guide (link below) https://developers.google.com/google-apps/calendar/v3/reference/events/insert

The code that I am using is nearly identical to the one provided by the API but it isn't working for some reason. The function draws the event properties from a form, assigns them to an event object and tries to add it to the calendar with the specified calendarId. It doesn't throw any errors but it does not add to the calendar even though it has authorization and is accessing the calendar in other parts of the program. Can anyone see what I am doing wrong or know how to make it work?

Here is the code I am using:

 function createNewEvent() {
        var sum = $("#eventName").val();
        var loc = $("#location").val();
        var desc = $("#descrip").val();
        var strt = $("#StartDateTime").val() + "+00:00";
        var endt = $("#EndDateTime").val() + "+00:00";
        var calId = $("#calendarList").val();

        var event = {
            'summary': sum,
            'location': loc,
            'description': desc,
            'start': { 'dateTime': strt },
            'end': { 'dateTime': endt }
        };


        var request = gapi.client.calendar.events.insert({
            'calendarId' : calId,
            'resource' : event
        });

        request.execute(function (event) {
            appendPre('Event created: ' + event.htmlLink);
        });
    }
kyapa
  • 1
  • 1
  • Are you sending the correct calendar Id in your request? Are you able to insert events from the try-it here https://developers.google.com/google-apps/calendar/v3/reference/events/insert – SGC Aug 10 '15 at 15:01
  • yes it works fine in in the try-it so the calendar Id is correct – kyapa Aug 10 '15 at 18:57
  • Then it should be problem with your code. For calId = $("#calendarList") give "primary" instead of calendar ID. Is start date and end date you are sending in the request are in RFC3339 format? – SGC Aug 10 '15 at 19:20
  • Below is the link. i hope this will work fine. https://stackoverflow.com/questions/11607465/need-good-example-google-calendar-api-in-javascript/11622475#11622475 – kashif azmi Jul 15 '20 at 16:11

0 Answers0