Delete Calendar Event permanently using Microsoft Graph API

Viewed 226

I am writing a scheduled service that writes public transport duty data into Exchange-Online calendars of bus drivers by using Microsaft Graph API. Since those duties may be splittet, changed or skipped at any day we have decided to delete previous entries on each process run and write new entries.

All that is working fine except that the deleted item after deletion end up in the deleted item mail folder. Is there any way to avoid that and delete permanentely?

1 Answers

When you delete calendar event then the deleted item mail folder will contain an item of @odata.type #microsoft.graph.eventMessageRequest

Get messages from the deleted item mail folder

var messages = await graphClient.Me.MailFolders["{id_of_deleted_item_mail_folder}"]
    .Messages
    .Request()
    .GetAsync();

// it returns items of Message type
// filter message of EventMessage which derives from Message

Delete the event message by calling

await graphClient.Me.MailFolders["{id_of_deleted_item_mail_folder"]
    .Messages["{event_message_id}"]
    .Request()
    .DeleteAsync();

It will remove the message from deleted item mail folder.

Resources:

Event message

Delete event message

Related