Get contact categories? #1381
|
I manage to get my contacts, but I have not yet found a way to access the categories I have assigned to them. Categories seem to be defined for messages, but not for contacts. Any hint? |
Replies: 1 comment 1 reply
|
Categories is actually defined on the base Item class (item:Categories in EWS), not on Message specifically. So Contact inherits it the same way Message, CalendarItem, and Task do. You should already be able to access it as a plain attribute: for contact in account.contacts.all():
print(contact.name, contact.categories)categories comes back as a list of strings (it's backed by exchangelib's CharListField), or None if no categories are assigned. contact = account.contacts.all()[0]
print(contact.categories) # should work even without .only()If it's still coming back empty/None for contacts you know have categories assigned in Outlook, worth confirming the categories were actually assigned at the item level in Outlook (and not, for instance, a master-category-list color label that didn't get saved onto that specific contact), but the field itself is definitely there and not message specific. |
Categories is actually defined on the base Item class (item:Categories in EWS), not on Message specifically. So Contact inherits it the same way Message, CalendarItem, and Task do. You should already be able to access it as a plain attribute:
categories comes back as a list of strings (it's backed by exchangelib's CharListField), or None if no categories are assigned.
If you're not seeing it, the most likely cause is that you are restricting the fields being fetched, via .only(...) on the queryset, or a custom additional_fields for fetch and categories just isn't in that list. Double check with: