Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Calendar.Insert API returning 400 'required'

I'm trying to create a calendar via the Google javascript API. OAuth authentication is working fine : I'm able to get a list of calendars using:

gapi.client.calendar.calendarList.list();

However, when I try to create a calendar with:

gapi.client.calendar.calendars.insert(
{
    "summary": "A New Calendar",
    "description": "Generated by Ben",
    "timezone" : "Australia/Sydney"
});

I get:

{
  "error": {
  "code": 400,
  "message": "Required",
  "data": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Required"
   }
  ]
 },
 "id": "gapiRpc"
}

In doco for other APIs it shows this response, but with a list of the required arguments that are missing.

Is there any way to determine what 'required' parameter I'm missing? I've tested it with the API Explorer and my parameters appear to work fine.

like image 934
Ben Hughes Avatar asked Feb 26 '12 14:02

Ben Hughes


1 Answers

Finally figured this out. The properties need to be in a 'resource' object:

gapi.client.calendar.calendars.insert(
{
    "resource" :
    {"summary": "A New Calendar",
    "description": "Generated by Ben",
    "timezone" : "Australia/Sydney"}
});

The doco doesn't mention this, but if you look at the response to the initial call to gapi.auth.authorize you'll find JSON describing the entire API for the scope you've specified.

like image 190
Ben Hughes Avatar answered Sep 28 '22 06:09

Ben Hughes