6

How to get/add/update Google Calendar Events using batch request through V3 REST API? I've tried and but not works. According to the docs (https://developers.google.com/google-apps/calendar/batch) it should be possible to send a batch request by posting a multipart/mixed content type message to the API. An example of a working HTTP POST would be great.

Thanks, Riyaz

Riyaz Ashraf
  • 163
  • 1
  • 10

3 Answers3

2

I found that the outer URL must be "https://www.googleapis.com/batch/calendar/v3/" and the boundary url must be "/calendar/v3/calendars/{calendarID}/events"

The full HTTP request looks like:

POST /batch/calendar/v3 HTTP/1.1
Authorization: /*Auth token*/
Host: host
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length

--batch_foobarbaz
Content-ID: 1

GET /calendar/v3/calendars/{calendarID1}/events

--batch_foobarbaz
Content-ID: 2

GET /calendar/v3/calendars/{calendarID2}/events

--batch_foobarbaz--
Grant_M
  • 106
  • 3
  • Can someone please explain to me, how to set this up using AJAX? Normally we send one AJAX request at a time, so I understand the Post request url is https://www.googleapis.com/batch/calendar/v3/, but then what are the GET requests doing? Are these to get events from the Google calendar into our application, after we've created the POST request? Sorry, I'm a little confused. – Ryan Sacks Oct 30 '21 at 02:01
1

The following batch request, gets the eventId1, updates the eventId2 and creates a new event under calender that is identified with calendarId.

POST /batch HTTP/1.1
Authorization: /*Auth token*/
Host: host
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length

--batch_foobarbaz
Content-Type: application/http
Content-ID: <item1:x@barnyard.example.com>

GET /calendar/v3/calendars/calendarId/events/eventId1

--batch_foobarbaz
Content-Type: application/http
Content-ID: <item2:x@barnyard.example.com>

PUT /calendar/v3/calendars/calendarId/events/eventId2
Content-Type: application/json
Content-Length: part_content_length

{{ body }}

--batch_foobarbaz
Content-Type: application/http
Content-ID: <item3:x@barnyard.example.com>

POST /calendar/v3/calendars/calendarId/events
Content-Type: application/json
Content-Length: part_content_length

{{ body }}

--batch_foobarbaz--
Burcu Dogan
  • 9,153
  • 4
  • 34
  • 34
  • what is the complete url that is to be used for /batch request. I tried using "http://www.googleapis.com/batch" but it failed...Please let me know – Jagadeesh Jul 16 '13 at 09:39
0

The endpoint is

https://www.googleapis.com/batch

That works for me when I do Calendar batch requests. One problem I had was with my last boundary token I didn't have the -- after it. So each token starts with -- and the last one has -- at the end. As @Burcu Dogan's example shows.

Jerinaw
  • 5,260
  • 7
  • 41
  • 54
  • Please note the endpoint 'https://www.googleapis.com/batch' has been shut down on August 12, 2020, and hence this is no longer valid. More info - https://developers.googleblog.com/2018/03/discontinuing-support-for-json-rpc-and.html – Avinash Kharche Sep 28 '21 at 00:08