Skip to content

Commit b2b41ca

Browse files
author
Yordy Gelvez
committed
README user guide
1 parent 6898617 commit b2b41ca

File tree

3 files changed

+488
-9
lines changed

3 files changed

+488
-9
lines changed

README.md

Lines changed: 273 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,273 @@
1-
# microsoftgraph-python
1+
# microsoft-python
2+
Microsoft graph API wrapper for Microsoft Graph written in Python.
3+
4+
## Installing
5+
```
6+
git+git://github.com/GearPlug/microsoftgraph-python
7+
```
8+
9+
## Usage
10+
```
11+
from microsoftgraph.client import Client
12+
client = Client('CLIENT_ID', 'CLIENT_SECRET', account_type='by defect common')
13+
```
14+
15+
#### Get authorization url
16+
for office 365
17+
```
18+
url = client.authorization_url(redirect_uri, scope, state=None, office365=True)
19+
```
20+
for microsoft graph
21+
```
22+
url = client.authorization_url(redirect_uri, scope, state=None, office365=False)
23+
```
24+
25+
#### Exchange the code for an access token
26+
for office 365
27+
```
28+
token = client.exchange_code(redirect_uri, code, office365=True)
29+
```
30+
for microsoft graph
31+
```
32+
token = client.exchange_code(redirect_uri, code, office365=False)
33+
```
34+
35+
#### Refresh token
36+
for office 365
37+
```
38+
token = client.refresh_token(redirect_uri, refresh_token, office365=True)
39+
```
40+
for microsoft graph
41+
```
42+
token = client.refresh_token(redirect_uri, refresh_token, office365=False)
43+
```
44+
45+
#### Set token
46+
for office 365
47+
```
48+
token = client.set_token(token, office365=True)
49+
```
50+
for microsoft graph
51+
```
52+
token = client.set_token(token, office365=False)
53+
```
54+
55+
#### Get me
56+
```
57+
me = client.get_me()
58+
```
59+
60+
#### Get message
61+
```
62+
me = client.get_message(message_id="")
63+
```
64+
65+
### Webhook section, see the api documentation: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/webhooks
66+
67+
#### Create subscription
68+
```
69+
subscription = client.create_subscription(change_type, notification_url, resource, expiration_datetime, client_state=None)
70+
```
71+
72+
#### Renew subscription
73+
```
74+
renew = client.renew_subscription(subscription_id, expiration_datetime)
75+
```
76+
77+
#### Delete subscription
78+
```
79+
renew = client.delete_subscription(subscription_id)
80+
```
81+
82+
### Onenote section, see the api documentation: https://developer.microsoft.com/en-us/graph/docs/concepts/integrate_with_onenote
83+
84+
#### List notebooks
85+
```
86+
notebooks = client.list_notebooks()
87+
```
88+
89+
#### Get notebook
90+
```
91+
notebook = client.get_notebook(notebook_id)
92+
```
93+
94+
#### Get notebook sections
95+
```
96+
section_notebook = client.get_notebook_sections(notebook_id)
97+
```
98+
99+
#### Create page
100+
```
101+
add_page = client.create_page(section_id, files)
102+
```
103+
104+
#### List pages
105+
```
106+
pages = client.list_pages()
107+
```
108+
109+
### Calendar section, see the api documentation: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/calendar
110+
111+
#### Get events
112+
```
113+
events = client.get_me_events()
114+
```
115+
116+
#### Create calendar event
117+
```
118+
events = client.create_calendar_event(subject, content, start_datetime, start_timezone, end_datetime, end_timezone,
119+
recurrence_type, recurrence_interval, recurrence_days_of_week, recurrence_range_type,
120+
recurrence_range_startdate, recurrence_range_enddate, location, attendees, calendar=None)
121+
```
122+
123+
#### Get calendars
124+
```
125+
events = client.get_me_calendars()
126+
```
127+
128+
#### Create calendar
129+
```
130+
events = client.create_calendar(name)
131+
```
132+
133+
### Contacts section, see the api documentation: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/contact
134+
135+
#### Get contacts
136+
If you need a specific contact send the contact id in data_id
137+
```
138+
specific_contact = client.outlook_get_me_contacts(data_id="")
139+
```
140+
If you want all the contacts
141+
```
142+
specific_contact = client.outlook_get_me_contacts()
143+
```
144+
145+
#### Create contact
146+
```
147+
add_contact = client.outlook_create_me_contact()
148+
```
149+
150+
#### Create contact in specific folder
151+
```
152+
add_contact_folder = client.outlook_create_contact_in_folder(folder_id)
153+
```
154+
155+
#### Get contact folders
156+
```
157+
folders = client.outlook_get_contact_folders()
158+
```
159+
160+
#### Create contact folders
161+
```
162+
add_folders = client.outlook_create_contact_folder()
163+
```
164+
165+
### Onedrive section, see the api documentation: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/onedrive
166+
167+
#### Get root items
168+
```
169+
root_items = client.drive_root_items()
170+
```
171+
172+
#### Get root children items
173+
```
174+
root_children_items = client.drive_root_children_items()
175+
```
176+
177+
#### Get specific folder items
178+
```
179+
folder_items = client.drive_specific_folder(folder_id)
180+
```
181+
182+
### Excel section, see the api documentation: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/excel
183+
For use excel, you should know the folder id where the file is
184+
#### Create session for specific item
185+
```
186+
create_session = client.drive_create_session(item_id)
187+
```
188+
189+
#### Refresh session for specific item
190+
```
191+
refresh_session = client.drive_refresh_session(item_id)
192+
```
193+
194+
#### Close session for specific item
195+
```
196+
close_session = client.drive_close_session(item_id)
197+
```
198+
199+
#### Get worksheets
200+
```
201+
get_worksheets = client.excel_get_worksheets(item_id)
202+
```
203+
204+
#### Get specific worksheet
205+
```
206+
specific_worksheet = client.excel_get_specific_worksheet(item_id, worksheet_id)
207+
```
208+
209+
#### Add worksheets
210+
```
211+
add_worksheet = client.excel_add_worksheet(item_id)
212+
```
213+
214+
#### Update worksheet
215+
```
216+
update_worksheet = client.excel_update_worksheet(item_id, worksheet_id)
217+
```
218+
219+
#### Get charts
220+
```
221+
get_charts = client.excel_get_charts(item_id, worksheet_id)
222+
```
223+
224+
#### Add chart
225+
```
226+
add_chart = client.excel_add_chart(item_id, worksheet_id)
227+
```
228+
229+
#### Get tables
230+
```
231+
get_tables = client.excel_get_tables(item_id)
232+
```
233+
234+
#### Add table
235+
```
236+
add_table = client.excel_add_table(item_id)
237+
```
238+
239+
#### Add column to table
240+
```
241+
add_column = client.excel_add_column(item_id, worksheets_id, table_id)
242+
```
243+
244+
#### Add row to table
245+
```
246+
add_row = client.excel_add_row(item_id, worksheets_id, table_id)
247+
```
248+
249+
#### Get table rows
250+
```
251+
get_rows = client.excel_get_rows(item_id, table_id)
252+
```
253+
254+
#### Get range
255+
```
256+
get_range = client.excel_get_range(item_id, worksheets_id)
257+
```
258+
259+
#### Update range
260+
```
261+
update_range = client.excel_update_range(item_id, worksheets_id)
262+
```
263+
264+
## Requirements
265+
- requests
266+
- base64
267+
- mimetypes
268+
- urllib.parse -- urlencode, --quote_plus
269+
270+
## Tests
271+
```
272+
test/test.py
273+
```

microsoftgraph/client.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def delete_subscription(self, subscription_id):
224224
"""
225225
return self._delete('https://graph.microsoft.com/beta/' + 'subscriptions/{}'.format(subscription_id))
226226

227+
# Onenote
227228
@token_required
228229
def list_notebooks(self):
229230
"""Retrieve a list of notebook objects.
@@ -287,6 +288,7 @@ def list_pages(self, params=None):
287288
"""
288289
return self._get(self.base_url + '/me/onenote/pages', params=params)
289290

291+
# Calendar
290292
@token_required
291293
def get_me_events(self):
292294
"""Get a list of event objects in the user's mailbox. The list contains single instance meetings and
@@ -408,6 +410,7 @@ def get_me_calendars(self):
408410
"""
409411
return self._get(self.base_url + 'me/calendars')
410412

413+
# Mail
411414
@token_required
412415
def send_mail(self, subject=None, recipients=None, body='', content_type='HTML', attachments=None):
413416
"""Helper to send email from current user.
@@ -451,6 +454,7 @@ def send_mail(self, subject=None, recipients=None, body='', content_type='HTML',
451454
# Do a POST to Graph's sendMail API and return the response.
452455
return self._post(self.base_url + 'me/microsoft.graph.sendMail', json=email_msg)
453456

457+
# Outlook
454458
@token_required
455459
def outlook_get_me_contacts(self, data_id=None, params=None):
456460
if data_id is None:
@@ -479,6 +483,7 @@ def outlook_create_contact_folder(self, **kwargs):
479483
url = "{0}me/contactFolders".format(self.base_url)
480484
return self._post(url, **kwargs)
481485

486+
# Onedrive
482487
@token_required
483488
def drive_root_items(self, params=None):
484489
return self._get('https://graph.microsoft.com/beta/me/drive/root', params=params)
@@ -508,6 +513,7 @@ def drive_close_session(self, item_id, **kwargs):
508513
url = "https://graph.microsoft.com/beta/me/drive/items/{0}/workbook/closeSession".format(item_id)
509514
return self._post(url, **kwargs)
510515

516+
# Excel
511517
@token_required
512518
def excel_get_worksheets(self, item_id, params=None, **kwargs):
513519
url = "https://graph.microsoft.com/beta/me/drive/items/{0}/workbook/worksheets".format(item_id)
@@ -568,15 +574,15 @@ def excel_get_rows(self, item_id, table_id, params=None, **kwargs):
568574
url = "https://graph.microsoft.com/beta/me/drive/items/{0}/workbook/tables/{1}/rows".format(item_id, table_id)
569575
return self._get(url, params=params, **kwargs)
570576

571-
@token_required
572-
def excel_get_cell(self, item_id, worksheets_id, params=None, **kwargs):
573-
url = "https://graph.microsoft.com/beta/me/drive/items/{0}/workbook/worksheets/{1}/Cell(row='1', column='A')".format(item_id, quote_plus(worksheets_id))
574-
return self._get(url, params=params, **kwargs)
577+
# @token_required
578+
# def excel_get_cell(self, item_id, worksheets_id, params=None, **kwargs):
579+
# url = "https://graph.microsoft.com/beta/me/drive/items/{0}/workbook/worksheets/{1}/Cell(row='1', column='A')".format(item_id, quote_plus(worksheets_id))
580+
# return self._get(url, params=params, **kwargs)
575581

576-
@token_required
577-
def excel_add_cell(self, item_id, worksheets_id, **kwargs):
578-
url = "https://graph.microsoft.com/beta/me/drive/items/{0}/workbook/worksheets/{1}/rows".format(item_id, worksheets_id)
579-
return self._patch(url, **kwargs)
582+
# @token_required
583+
# def excel_add_cell(self, item_id, worksheets_id, **kwargs):
584+
# url = "https://graph.microsoft.com/beta/me/drive/items/{0}/workbook/worksheets/{1}/rows".format(item_id, worksheets_id)
585+
# return self._patch(url, **kwargs)
580586

581587
@token_required
582588
def excel_get_range(self, item_id, worksheets_id, **kwargs):

0 commit comments

Comments
 (0)