Google Calendar API batch inserting has stopped working

Viewed 557

I have an application that has been successfully using HTTP batch requests to insert, edit, and delete events via the Google Calendar API. In the last couple of days, the individual requests within the batches have started returning 404 errors (although the batch itself gets a 200 success response). Making those same requests as individual requests using the same authorization header is still working.

I'm pretty sure that this isn't related to the forthcoming shutdown of Google's global HTTP batch endpoints because we're using https://www.googleapis.com/batch/calendar/v3 as our endpoint.

Here's an example of what I'm trying to do:

https://www.googleapis.com/batch/calendar/v3
Authorization: Bearer your_auth_token
Content-Type: multipart/mixed; boundary=batch_google_calendar

--batch_google_calendar
Content-Type: application/http
Content-ID: <item-0-batchevent@example.com>

POST calendar/v3/calendars/your_calendar_id@group.calendar.google.com/events
Content-Type: application/json

{"summary":"batch API test","start":{"date":"2020-07-31"},"end":{"date":"2020-07-31"}}
--batch_google_calendar--

And the response is:

--batch_3J6sfuPtVQbjZLcpUe06245gKlO31YnC
Content-Type: application/http
Content-ID: <response-item-0-batchevent@example.com>

HTTP/1.1 404 Not Found
Vary: Origin
Vary: X-Origin
Vary: Referer
Content-Type: application/json; charset=UTF-8

[{
  "error": {
    "code": 404,
    "message": "URL path: /v3/calendars/your_calendar_id@group.calendar.google.com/events could not be resolved. Maybe there is an error parsing the batch item.",
    "status": "NOT_FOUND"
  }
}
]
--batch_3J6sfuPtVQbjZLcpUe06245gKlO31YnC--

And here's an example of an individual request that's working:

https://www.googleapis.com/calendar/v3/calendars/your_calendar_id@group.calendar.google.com/events
Authorization: Bearer your_auth_token
Content-Type: application/json

{"summary":"API test","start":{"date":"2020-07-31"},"end":{"date":"2020-07-31"}}

Why might the individual request be succeeding but the batch request fail?

1 Answers

Google gave a helpful reply via their issue tracker: there was an error in the way that batch entry paths were specific in my application. This had worked without errors until last week, so I think something must have changed at their end to make it less tolerant of mistakes.

The error we had made was omitting the leading slash in the path in each batch entry. Here's what we were doing:

POST calendar/v3/calendars/your_calendar_id@group.calendar.google.com/events

And here's what we should have been doing:

POST /calendar/v3/calendars/your_calendar_id@group.calendar.google.com/events

I hope that this might be helpful to anyone else who ever finds themselves in a similar situation!

Related