0

I am using Exchangelib with service account credentials to impersonate individual EWS users. I am able to retrieve a list of calendars the user has access to, but this list does not include personal calendars shared with the user.

Example: Jane has a default calendar named "Calendar", and they share this calendar with Bill. Jane also has a second calendar they created and shared with Bill named "Interviews".

When I list Bill's calendars, I can only see the "Interviews" calendar - Jane's default calendar is not listed.

I am iterating over the Account() object's calendar.children:

>>> ews_account = Account(
                primary_smtp_address=XXXXX,
                config=XXXXX,
                autodiscover=False,
                access_type=IMPERSONATION,
            )

>>> for calendar in ews_account.calendar.children:
>>>     print(calendar.name)
"Interviews"

Is there a different way to find out that Jane has shared her personal calendar with Bill?

It looks like there's a method to send the calendar ID along with Jane's email address to see if it's shared with Bill, but I'm hoping for a way to list all of these without knowing the calendar ID and email address in advance.

These personal calendars were shared with "delegate" level access, but I also tried sharing with "Can Edit" access.

ZZZZZ
  • 3
  • 1

1 Answers1

0

I was able to solve the problem in a slightly different way with this code based on the Stackoverflow answer.

First I instantiate the base account using IMPERSONATION, and then I use GetFolder using the account context of the original account, and setting mailbox to the other user's email address.

For this to work, you have to know the email address of the owner of the shared calendar, which is not ideal. In the comments, Glen Scales indicates you can look up these shared calendars directly on the original account using NavLinks but I wasn't able to figure that out: EWS - Access All Shared Calendars

from exchangelib import (
    IMPERSONATION,
    Account,
    Configuration,
    Mailbox,
    folders
)
from exchangelib.fields import FieldPath
from exchangelib.items import ID_ONLY
from exchangelib.services import GetFolder

account = Account(
    primary_smtp_address="test@example.com",
    config=Configuration(
        server=...,
        credentials=...,
    ),
    autodiscover=True,
    access_type=IMPERSONATION,
)

shared_calendar = next(
    GetFolder(account=account).call(
        folders=[
            folders.DistinguishedFolderId(
                id=folders.Calendar.DISTINGUISHED_FOLDER_ID,
                mailbox=Mailbox(
                    email_address="other_user@example.com"
                ),
            )
        ],
        additional_fields={
            FieldPath(field=field)
            for field in account.calendar.supported_fields(
                version=account.version
            )
        },
        shape=ID_ONLY,
    )
)
ZZZZZ
  • 3
  • 1