dav
dav copied to clipboard
Is it possible to clear all objects from a specific calendar?
Hey!
Is there a way to reset / clear a calendar?
I tried to run this code:
const dav = require('dav');
var xhr = new dav.transport.Basic(
new dav.Credentials({
username: '****USER****',
password: '****PASSWORD****'
})
);
var client = new dav.Client(xhr);
client.createAccount({
server: '****SERVER URL****',
accountType: 'caldav',
loadObjects: true
}).then((account) => {
const calendar = account.calendars[0];
// get all events from calendar
calendar.objects.forEach((calendarObject) => {
// remove current event from calendar
client.deleteCalendarObject(calendarObject, {
xhr: xhr
});
});
});
to remove all objects of a calendar, but unfortunately it does not work properly, im always getting this error:
(node:7783) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 335)
(node:7783) UnhandledPromiseRejectionWarning: Error: Bad status: 412
Maybe anyone here can help me :)
Thanks, Mike