Update of Outlook Calendar Categories issue #907
aadslingerland
started this conversation in
General
Replies: 2 comments
-
This issue has ben solved.... By myself. Changed the code "read_event.categories.append ("My Category")" to "read_event.categories ("My Category")" |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Greetings,
I'm having an issue with adding an item to the Outlook Calendar Categories.
When adding a category to a new event everything is okay. The category I added shows in the Outlook user interface and in the event object model (of course). In other words when my application adds a new Outlook Calendar Event all is okay.
But, when adding a category to an already existing Outlook Calendar Event (created by a user) the result is NOT okay.
I included Python code for both situations below. Is there something wrong with my code or ...?
`
OutlookCalendarCategoryOkay.py
import os
import Config
import datetime as dt
from O365 import Account
from O365 import Connection
from O365 import FileSystemTokenBackend
if name == 'main':
creds = (Config.OUTLOOK_CLIENT_ID, Config.OUTLOOK_CLIENT_SECRET)
token_backend = FileSystemTokenBackend(token_path=os.path.join (os.getcwd(), Config.SECRETS_PATH), token_filename= Config.AZURE_TOKEN_FILE)
account = Account(creds, token_backend=token_backend)
#
# My calendar
#
my_calendar = account.schedule().get_default_calendar()
#
# Create a new Outlook Calendar event and fill some properties including a category.
#
new_event = my_calendar.new_event()
new_event.subject = "Category Test"
new_event.start = dt.datetime(2022, 12, 12, 12, 12)
new_event.categories.append ("My Category")
result = new_event.save()
#
# Read back the Outlook Calendar event and have a look at the category property.
#
read_event = my_calendar.get_event (new_event.object_id)
print (read_event.categories)
#
# okay!
#
`
`
OutlookCalendarCategoryNotOkay.py
import os
import time
import Config
import datetime as dt
from O365 import Account
from O365 import Connection
from O365 import FileSystemTokenBackend
if name == 'main':
creds = (Config.OUTLOOK_CLIENT_ID, Config.OUTLOOK_CLIENT_SECRET)
token_backend = FileSystemTokenBackend(token_path=os.path.join (os.getcwd(), Config.SECRETS_PATH), token_filename= Config.AZURE_TOKEN_FILE)
account = Account(creds, token_backend=token_backend)
#
# My calendar
#
my_calendar = account.schedule().get_default_calendar()
#
# Create a new Outlook Calendar event and fill some properties but not yet a category.
#
new_event = my_calendar.new_event()
new_event.subject = "Category Test"
new_event.start = dt.datetime(2022, 12, 12, 12, 12)
result = new_event.save()
object_id = new_event.object_id
del new_event
#
# Read back the Outlook Calendar event at some later point in time with the goal to add the category property.
#
time.sleep (1) # in my app this could be 5 minutes, 5 hours, whatever.
read_event = my_calendar.get_event (object_id)
read_event.categories.append ("My Category")
#
# save the updated event...
#
result = read_event.save()
del read_event
#
# ... and read it back to inspect the result
#
inspect_event = my_calendar.get_event (object_id)
print (inspect_event.categories)
#
# NOT okay! NO Categories.
#
`
Beta Was this translation helpful? Give feedback.
All reactions