1
List Calendars in Nextcloud Calendar
One script reply has been approved by the moderators Verified

List all calendars a user has access to in Nextcloud calendar.

Created by marcel klehr12 179 days ago Viewed 345 times
0
Submitted by marcel klehr12 Python3
Verified 179 days ago
1
import caldav
2
import base64
3

4
# You can import any PyPi package.
5
# See here for more info: https://www.windmill.dev/docs/advanced/dependencies_in_python
6

7
# you can use typed resources by doing a type alias to dict
8
nextcloud = dict
9

10

11
def main(NextcloudResource: nextcloud, userId: str, useAppApiAuth: bool = False):
12
    if useAppApiAuth:
13
        headers = {
14
            "AA-VERSION": "2.3.0",
15
            "EX-APP-ID": "flow",
16
            "EX-APP-VERSION": "1.0.0",
17
            "AUTHORIZATION-APP-API": base64.b64encode(
18
              f"{userId}:{NextcloudResource['password']}".encode('utf-8')).decode('utf-8'),
19
          }
20
    else:
21
        headers = {}
22

23
    with caldav.DAVClient(
24
        url=NextcloudResource['baseUrl'] + '/remote.php/dav/calendars/'+userId+'/',
25
        username=userId,
26
        password=NextcloudResource['password'],
27
        headers=headers,
28
    ) as client:
29
        my_principal = client.principal()
30
        return my_principal.calendars()
31