I have this python code below to create a meeting event, and it is working. I plan to incorporate this script with the Web Form submision where user enters some basic information such as Subject, attendees, and meeting date/time, and then the Python script will create a meeting event based on submitted info from the web form. That I have no problem to accomplish, but the problem is the timezone of the meeting.
As you can see the Python script requires Start/End time as this ""2016-08-03T15:00:00-07:00" (the -07:00 is for PDT time). However, the web form does not know what timezone of current user (users could be in West, Mountain, Central, or East timezone). It is too complicate to figure out the timezone is -7(PDT), -8(PST), -6(CT)....
Is there a way to query the current time zone setting of the person who creates the meeting based on user login? Then convert that timezone to number (-7 for PDT, -8 for PST, -6 CT...)... so the "StartTimeZone" and "EndTimeZone" have the correct time?
# Set the request parameters
url = 'https://outlook.office365.com/api/v1.0/me/events?$Select=Start,End'
user = 'user1@domain.com'
pwd = getpass.getpass('Please enter your AD password: ')
# Create JSON payload
data = {
"Subject": "Testing Outlock Event",
"Body": {
"ContentType": "HTML",
"Content": "Test Content"
},
"Start": "2016-08-03T15:00:00-07:00",
"StartTimeZone": "Pacific Standard Time",
"End": "2016-08-03T16:00:00-07:00",
"EndTimeZone": "Pacific Standard Time",
"Attendees": [
{
"EmailAddress": {
"Address": "attendee1@domain.com",
"Name": "User2"
},
"Type": "Required" },
{
"EmailAddress": {
"Address": "attendee2@domain.com",
"Name": "User3"
},
"Type": "Optional" }
]
}
json_payload = json.dumps(data)
# Build the HTTP request
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request(url, data=json_payload)
auth = base64.encodestring('%s:%s' % (user, pwd)).replace('\n', '')
request.add_header('Authorization', 'Basic %s' % auth)
request.add_header('Content-Type', 'application/json')
request.add_header('Accept', 'application/json')
request.get_method = lambda: 'POST'
# Perform the request
result = opener.open(request)