Search code examples
javaapiexchangewebservices

EWS API - The specified folder could not be found in the store if share Calendar with FolderPermissionLevel.FreeBusyTimeAndSubjectAndLocation


I'm trying to automate next scenario with EWS API:

  • user1 shares his calendar with user2 with permission level 'FreeBusyTimeAndSubjectAndLocation'
  • user1 creates an event in his calendar
  • user2 tries to get info about user1 event

Method to set permission

public void iWantFolderPermission(String email) throws Exception {
    PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, FolderSchema.Permissions);
    // Specify the SMTP address of the new user and the folder permissions level.
    FolderPermission fldperm = new FolderPermission(email, FolderPermissionLevel.FreeBusyTimeAndSubjectAndLocation);

    // Bind to the folder and get the current permissions.
    // This call results in a GetFolder call to EWS.
    Folder sentItemsFolder = Folder.bind(service, WellKnownFolderName.Calendar, propSet);

    // Add the permissions for the new user to the Sent Items DACL.
    sentItemsFolder.getPermissions().add(fldperm);
    // This call results in a UpdateFolder call to EWS.
    sentItemsFolder.update();
}

But when I try to get event from shared Calendar I get an error - microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: The specified folder could not be found in the store.

If I set permission to FolderPermissionLevel.Reviewer then everything works just fine. So why shared Calendar can not be accessed with permission level FreeBusyTimeAndSubjectAndLocation?


Solution

  • FreeBusyTimeAndSubjectAndLocation only gives you access to a limited subset of information when using the GetUserAvailiblity operation https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/getuseravailability-operation the Appointment details are then returned in CalendarEventArray. To be able to access the folderitems directly you need to have at least reviewer rights.