Work with calendars#
List calendars#
calendars = client.get_calendars()
for cal in calendars:
print(cal.id, cal.name, cal.color)
Each item is a JMAPCalendar; see objects: JMAP data objects for its fields.
Pass account_id to list calendars on another account that’s been shared with you:
calendars = client.get_calendars(account_id=other_account_id)
Create a calendar#
calendar_id = client.create_calendar(name="Team events", color="#2E86AB")
name is required. color and timezone are optional.
Update a calendar#
client.update_calendar(calendar_id, name="Team events (archived)")
Only the arguments you pass change; the rest are left alone. name, color, and timeZone are per-user: updating them as the calendar’s owner changes what every sharee sees, until a sharee sets their own override on top.
Delete a calendar#
client.delete_calendar(calendar_id)
Deleting a calendar that still has events raises JMAPMethodError with error_type "calendarHasEvent", rather than deleting anything, unless you pass on_destroy_remove_events=True:
client.delete_calendar(calendar_id, on_destroy_remove_events=True)
Set default alerts#
New events created on a calendar can inherit default alerts, one set for timed events and one for all-day events:
client.set_default_alerts(
calendar_id,
alerts_with_time={"a1": {"@type": "Alert", "trigger": {"@type": "OffsetTrigger", "offset": "-PT15M"}}},
alerts_without_time={},
)
Pass None (the default) for either argument to leave it unchanged; pass {} to clear it.
Subscriptions#
subscribed = client.get_calendar_subscriptions()
Equivalent to filtering get_calendars() to is_subscribed; JMAP Calendars has no separate subscription object.