Reputation: 41
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?
Upvotes: 4
Views: 5078
Reputation: 31
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
Upvotes: 3
Reputation: 1691
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!!!')
});
}
Upvotes: 2
Reputation: 13469
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.
Upvotes: 1