Getting Error: Google.Apis.Requests.RequestError Bad Request [400] Errors When I Attempt to Create an Event using .NET Client

4,777 views
Skip to first unread message

Dan B

unread,
Dec 9, 2011, 5:11:09 PM12/9/11
to google-ca...@googlegroups.com
Everything else is working fine.
I can Authorize, get calendars, get events and Quick add an event on any calendar. But for some reason I am getting an error when I try to create an event using:
  Event request = service.Events.Insert(testEvent, calendarID).Fetch();

I am using VS2010 .Net 4.0 and c:\googlecode\11-23-2011\

I get the same errors no matter which calendar or google account I use.

Any thoughts on what might be wrong?
Thanks,
Dan B

Here is the code:
Event testEvent = new Event();
            DateTime startDate=DateTime.Now.AddMinutes(30);

            testEvent.Description = "This is a test event generated by me";
            testEvent.Start = new EventDateTime();
            testEvent.Start.DateTime =startDate.ToString();
            testEvent.End = new EventDateTime();
            testEvent.End.DateTime = startDate.AddMinutes(30).ToString();
            testEvent.Summary = "Test Event";
            EventReminder reminder = new EventReminder();
            reminder.Method = "popup";
            reminder.Minutes = 30;
            testEvent.Reminders = new Event.RemindersData();
            testEvent.Reminders.Overrides = new List<EventReminder>();
            testEvent.Reminders.Overrides.Add(reminder);
            testEvent.Reminders.UseDefault = false;
            testEvent.Visibility = "public";
            testEvent.Attendees = new List<EventAttendee>();
               EventAttendee ea = new EventAttendee();
                 ea.DisplayName="Dan B";
                 ea.Organizer=true;
                 testEvent.Attendees.Add(ea);
            var service = new CalendarService(auth);
           Event request = service.Events.Insert(testEvent, calendarID).Fetch();

Here is the URL it is requesting
{Google.Apis.Requests.Request(insert @ https://www.googleapis.com/calendar/v3/calendars/calendarID/events?alt=json&prettyPrint=true)}

Here is the Stack Trace:

Google.GoogleApiRequestException was unhandled
  Message=Google.Apis.Requests.RequestError
Bad Request [400]
Errors [
    Message[Bad Request] Location[ - ] Reason[badRequest] Domain[global]
]

  Source=Google.Apis
  StackTrace:
       at Google.Apis.Requests.Request.AsyncRequestResult.GetResponse() in c:\googlecode\11-23-2011\default\Src\GoogleApis\Apis\Requests\Request.cs:line 300
       at Google.Apis.Requests.ServiceRequest`1.GetResponse() in c:\googlecode\11-23-2011\default\Src\GoogleApis\Apis\Requests\ServiceRequest.cs:line 183
       at Google.Apis.Requests.ServiceRequest`1.Fetch() in c:\googlecode\11-23-2011\default\Src\GoogleApis\Apis\Requests\ServiceRequest.cs:line 203
       at GoogleCalStuff.AuthForm.btnCreateEvent_Click(Object sender, EventArgs e) in C:\DEV\GoogleCalStuff\GoogleCalStuff\AuthForm.cs:line 272
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at GoogleCalStuff.Program.Main() in C:\DEV\GoogleCalStuff\GoogleCalStuff\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Net.WebException
       Message=The remote server returned an error: (400) Bad Request.
       Source=System
       StackTrace:
            at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
            at Google.Apis.Requests.Request.InternalEndExecuteRequest(IAsyncResult asyncResult) in c:\googlecode\11-23-2011\default\Src\GoogleApis\Apis\Requests\Request.cs:line 326
       InnerException:

Rodrigo Campero Paz

unread,
Dec 9, 2011, 9:14:43 PM12/9/11
to google-ca...@googlegroups.com
I'm having the same problem, any thoughts? is a bug? 

Thank you very much.

Alain Vongsouvanh

unread,
Dec 12, 2011, 12:20:14 PM12/12/11
to google-ca...@googlegroups.com
Hello,

There is usually a explicit message along with the error code explaining what the bad request is about. You need to catch the exception and print the message.
Also, please have a look at the Using Guide explaining the requirements for timed-events:

Best,
Alain

On Fri, Dec 9, 2011 at 6:14 PM, Rodrigo Campero Paz <ros...@gmail.com> wrote:
I'm having the same problem, any thoughts? is a bug? 

Thank you very much.

--
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/-/V0rCaRs8NiAJ.

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.



--
Alain Vongsouvanh | Developer Programs Engineer

Dan B

unread,
Dec 12, 2011, 4:36:58 PM12/12/11
to google-ca...@googlegroups.com
Hi,
Thanks for pointing out the date format stuff. I jumped straight to the Creating Events section in the Developers guide, so I totally missed that. In addition to the date stuff there was another error in the code I pasted above. So once I figured out how to get the dates into rfc 3339 format and got rid of the attendee stuff it worked fine.

I wasn't quite sure what you meant about the explicit message, as I pasted the Exception.Message and the Stack Trace in the original post. The only other error I could find was buried in the Exception report generated by VS 2010:

'((Google.Apis.Discovery.BaseService)(((Google.GoogleApiException)($exception)).Service)).RpcUri' threw an exception of type 'System.Collections.Generic.KeyNotFoundException'


Anyway, thanks again.
-Dan B.

Alain Vongsouvanh

unread,
Dec 13, 2011, 12:19:59 PM12/13/11
to google-ca...@googlegroups.com
Hello,

The API usually returns an error message in the body along with the HTTP status code that would try to explain what the issue was. If you try your request in the APIs Explorer, you should be able to see the error message.

Best,
Alain

--
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.
Reply all
Reply to author
Forward
0 new messages