1- # Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file .
1+ # Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE.txt in the project root for license information .
22import requests
33import uuid
44import json
55
6- outlook_api_endpoint = 'https://outlook.office .com/api/v2 .0{0}'
6+ graph_endpoint = 'https://graph.microsoft .com/v1 .0{0}'
77
88# Generic API Sending
99def make_api_call (method , url , token , user_email , payload = None , parameters = None ):
@@ -38,11 +38,11 @@ def make_api_call(method, url, token, user_email, payload = None, parameters = N
3838 return response
3939
4040def get_me (access_token ):
41- get_me_url = outlook_api_endpoint .format ('/Me ' )
41+ get_me_url = graph_endpoint .format ('/me ' )
4242
4343 # Use OData query parameters to control the results
44- # - Only return the DisplayName and EmailAddress fields
45- query_parameters = {'$select' : 'DisplayName,EmailAddress ' }
44+ # - Only return the displayName and mail fields
45+ query_parameters = {'$select' : 'displayName,mail ' }
4646
4747 r = make_api_call ('GET' , get_me_url , access_token , "" , parameters = query_parameters )
4848
@@ -52,15 +52,15 @@ def get_me(access_token):
5252 return "{0}: {1}" .format (r .status_code , r .text )
5353
5454def get_my_messages (access_token , user_email ):
55- get_messages_url = outlook_api_endpoint .format ('/Me/MailFolders/Inbox/Messages ' )
55+ get_messages_url = graph_endpoint .format ('/me/mailfolders/inbox/messages ' )
5656
5757 # Use OData query parameters to control the results
5858 # - Only first 10 results returned
5959 # - Only return the ReceivedDateTime, Subject, and From fields
6060 # - Sort the results by the ReceivedDateTime field in descending order
6161 query_parameters = {'$top' : '10' ,
62- '$select' : 'ReceivedDateTime,Subject,From ' ,
63- '$orderby' : 'ReceivedDateTime DESC' }
62+ '$select' : 'receivedDateTime,subject,from ' ,
63+ '$orderby' : 'receivedDateTime DESC' }
6464
6565 r = make_api_call ('GET' , get_messages_url , access_token , user_email , parameters = query_parameters )
6666
@@ -70,15 +70,15 @@ def get_my_messages(access_token, user_email):
7070 return "{0}: {1}" .format (r .status_code , r .text )
7171
7272def get_my_events (access_token , user_email ):
73- get_events_url = outlook_api_endpoint .format ('/Me/Events ' )
73+ get_events_url = graph_endpoint .format ('/me/events ' )
7474
7575 # Use OData query parameters to control the results
7676 # - Only first 10 results returned
7777 # - Only return the Subject, Start, and End fields
7878 # - Sort the results by the Start field in ascending order
7979 query_parameters = {'$top' : '10' ,
80- '$select' : 'Subject,Start,End ' ,
81- '$orderby' : 'Start/DateTime ASC' }
80+ '$select' : 'subject,start,end ' ,
81+ '$orderby' : 'start/dateTime ASC' }
8282
8383 r = make_api_call ('GET' , get_events_url , access_token , user_email , parameters = query_parameters )
8484
@@ -88,40 +88,19 @@ def get_my_events(access_token, user_email):
8888 return "{0}: {1}" .format (r .status_code , r .text )
8989
9090def get_my_contacts (access_token , user_email ):
91- get_contacts_url = outlook_api_endpoint .format ('/Me/Contacts ' )
91+ get_contacts_url = graph_endpoint .format ('/me/contacts ' )
9292
9393 # Use OData query parameters to control the results
9494 # - Only first 10 results returned
9595 # - Only return the GivenName, Surname, and EmailAddresses fields
9696 # - Sort the results by the GivenName field in ascending order
9797 query_parameters = {'$top' : '10' ,
98- '$select' : 'GivenName,Surname,EmailAddresses ' ,
99- '$orderby' : 'GivenName ASC' }
98+ '$select' : 'givenName,surname,emailAddresses ' ,
99+ '$orderby' : 'givenName ASC' }
100100
101101 r = make_api_call ('GET' , get_contacts_url , access_token , user_email , parameters = query_parameters )
102102
103103 if (r .status_code == requests .codes .ok ):
104104 return r .json ()
105105 else :
106- return "{0}: {1}" .format (r .status_code , r .text )
107-
108- # MIT License:
109-
110- # Permission is hereby granted, free of charge, to any person obtaining
111- # a copy of this software and associated documentation files (the
112- # ""Software""), to deal in the Software without restriction, including
113- # without limitation the rights to use, copy, modify, merge, publish,
114- # distribute, sublicense, and/or sell copies of the Software, and to
115- # permit persons to whom the Software is furnished to do so, subject to
116- # the following conditions:
117-
118- # The above copyright notice and this permission notice shall be
119- # included in all copies or substantial portions of the Software.
120-
121- # THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
122- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
123- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
124- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
125- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
126- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
127- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
106+ return "{0}: {1}" .format (r .status_code , r .text )
0 commit comments