I am using google API, https://developers.google.com/calendar/v3/reference/events/insert to insert event in calendar. Single event is inserted successfully, but is there a way we can insert multiple events in a single callout?
-
1Possible duplicate of [Google Calendar javascript api - Add multiple events](https://stackoverflow.com/questions/15487238/google-calendar-javascript-api-add-multiple-events) – ADyson May 24 '18 at 11:51
3 Answers
You need to use batch to add / delete / update events.
Why use batch? The primary reason to use the batch API is to reduce network overhead and thus increase performance.
Here is an example showing the usage of batch to add events dynamically using javascript / typescript,
createMultipleEvents() {
const events = [ {
'summary': 'sample test events1',
'location': 'coimbatore',
'start': {
'date': '2018-08-29',
'timeZone': 'America/Los_Angeles'
},
'end': {
'date': '2018-08-29',
'timeZone': 'America/Los_Angeles'
}
},
{
'summary': 'sample test events2',
'location': 'coimbatore',
'start': {
'date': '2018-08-29',
'timeZone': 'America/Los_Angeles'
},
'end': {
'date': '2018-08-29',
'timeZone': 'America/Los_Angeles'
}
},
];
const batch = gapi.client.newBatch();
events.map((r, j) => {
batch.add(gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': events[j]
}))
})
batch.then(function(){
console.log('all jobs now dynamically done!!!')
});
}

- 1,499
- 2
- 18
- 39
Global HTTP Batch Endpoints (www.googleapis.com/batch) will cease to work on August 12, 2020 as announced on the Google Developers blog. For instructions on transitioning services to use API-specific HTTP Batch Endpoints (www.googleapis.com/batch/api/version), refer to the blog post. https://developers.googleblog.com/2018/03/discontinuing-support-for-json-rpc-and.html

- 21
- 1
As stated in this thread, if you want to insert multiple events at once, you should use batch.
var batch = gapi.client.newBatch();
batch.add(gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': events[0]
}));
batch.add(gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': events[1]
}));
batch.add(gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': events[2]
}));
......
batch.then(function(){
console.log('all jobs done!!!')
});
You may also check this link for additional reference.