Skip to content

Instantly share code, notes, and snippets.

@samwelkanda
Last active December 15, 2023 10:48
Show Gist options
  • Save samwelkanda/45fd00fd0dc0decdb68a90e8ae9a8abc to your computer and use it in GitHub Desktop.
Save samwelkanda/45fd00fd0dc0decdb68a90e8ae9a8abc to your computer and use it in GitHub Desktop.
# Find meeting times
from datetime import timedelta
from msgraph.generated.models.activity_domain import ActivityDomain
from msgraph.generated.models.attendee_base import AttendeeBase
from msgraph.generated.models.attendee_type import AttendeeType
from msgraph.generated.models.date_time_time_zone import DateTimeTimeZone
from msgraph.generated.models.email_address import EmailAddress
from msgraph.generated.models.location_constraint import LocationConstraint
from msgraph.generated.models.location_constraint_item import LocationConstraintItem
from msgraph.generated.models.time_constraint import TimeConstraint
from msgraph.generated.models.time_slot import TimeSlot
from msgraph.generated.users.item.find_meeting_times.find_meeting_times_post_request_body import FindMeetingTimesPostRequestBody
from msgraph.generated.users.item.find_meeting_times.find_meeting_times_request_builder import FindMeetingTimesRequestBuilder
async def find_meeting_times():
request_body = FindMeetingTimesPostRequestBody()
attendee1 = AttendeeBase()
attendee1.type = AttendeeType.Required
attendee1_email_address = EmailAddress()
attendee1_email_address.name = 'Alex Wilber'
attendee1_email_address.address = '[email protected]'
attendee1.email_address = attendee1_email_address
request_body.attendees = [attendee1]
location_constraint = LocationConstraint()
location_constraint.is_required = False
location_constraint.suggest_location = False
location_constraint_item1 = LocationConstraintItem()
location_constraint_item1.resolve_availability = False
location_constraint_item1.display_name = 'Conf Room Hood'
location_constraint.locations = [location_constraint_item1]
request_body.location_constraint = location_constraint
time_constraint = TimeConstraint()
time_constraint.activity_domain = ActivityDomain.Work
time_slot1 = TimeSlot()
time_slot1_start = DateTimeTimeZone()
time_slot1_start.date_time = '2019-04-16T09:00:00'
time_slot1_start.time_zone = 'Pacific Standard Time'
time_slot1.start = time_slot1_start
time_slot1_end = DateTimeTimeZone()
time_slot1_end.date_time = '2019-04-18T17:00:00'
time_slot1_end.time_zone = 'Pacific Standard Time'
time_slot1.end = time_slot1_end
time_constraint.time_slots = [time_slot1]
request_body.time_constraint = time_constraint
request_body.is_organizer_optional = False
request_body.meeting_duration = timedelta(hours=1)
request_body.return_suggestion_reasons = True
request_body.minimum_attendee_percentage = 100
request_config = FindMeetingTimesRequestBuilder.FindMeetingTimesRequestBuilderPostRequestConfiguration(
headers={"prefer": 'outlook.timezone="Pacific Standard Time"'}
)
try:
result = await client.users_by_id('[email protected]').find_meeting_times.post(request_body, request_config)
if result:
print(result.empty_suggestions_reason)
if result.meeting_time_suggestions:
for suggestion in result.meeting_time_suggestions:
print(suggestion.confidence, suggestion.organizer_availability, suggestion.suggestion_reason)
except APIError as e:
print(e.error.message, e.error.code)
asyncio.run(find_meeting_times())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment