0
# User Management
1
2
User profile operations, enrollment handling, file management, communication channels, and user-specific Canvas functionality. The User class provides comprehensive access to user data and capabilities.
3
4
## Capabilities
5
6
### Profile Management
7
8
Manage user profiles, personal information, and account settings.
9
10
```python { .api }
11
class User(CanvasObject):
12
def get_profile(self, **kwargs) -> dict:
13
"""
14
Get user profile information.
15
16
Returns:
17
Dictionary with profile data including name, email, bio, avatar_url, etc.
18
"""
19
20
def edit(self, **kwargs) -> User:
21
"""
22
Edit user profile.
23
24
Parameters:
25
- name: User's full name
26
- short_name: User's display name
27
- sortable_name: Name for sorting (Last, First)
28
- email: Primary email address
29
- bio: User biography
30
- pronouns: User pronouns
31
32
Returns:
33
Updated User object
34
"""
35
36
def get_avatars(self, **kwargs) -> PaginatedList[Avatar]:
37
"""Get available avatars for the user."""
38
```
39
40
### Course and Enrollment Access
41
42
Access user's courses, enrollments, and academic information.
43
44
```python { .api }
45
def get_courses(self, **kwargs) -> PaginatedList[Course]:
46
"""
47
List courses for the user.
48
49
Parameters:
50
- enrollment_type: Filter by enrollment type ('student', 'teacher', 'ta', etc.)
51
- enrollment_role: Filter by specific role
52
- enrollment_state: Filter by enrollment state ('active', 'invited', 'completed')
53
- include: Additional data ('needs_grading_count', 'syllabus_body', etc.)
54
- state: Filter by course workflow state ('available', 'completed', 'deleted')
55
56
Returns:
57
Paginated list of Course objects
58
"""
59
60
def get_enrollments(self, **kwargs) -> PaginatedList[Enrollment]:
61
"""
62
List enrollments for the user.
63
64
Parameters:
65
- type: Filter by enrollment type
66
- role: Filter by enrollment role
67
- state: Filter by enrollment state
68
- include: Additional data ('avatar_url', 'group_ids', 'locked', etc.)
69
70
Returns:
71
Paginated list of Enrollment objects
72
"""
73
74
def get_missing_submissions(self, **kwargs) -> PaginatedList[Assignment]:
75
"""
76
Get assignments with missing submissions for the user.
77
78
Parameters:
79
- include: Additional data ('course', 'planner_override')
80
- filter: Date range filter
81
82
Returns:
83
Paginated list of Assignment objects with missing submissions
84
"""
85
```
86
87
### Assignment and Academic Work
88
89
Access user's assignments, submissions, and academic progress.
90
91
```python { .api }
92
def get_assignments(self, **kwargs) -> PaginatedList[Assignment]:
93
"""
94
List assignments for the user across all courses.
95
96
Parameters:
97
- course_ids: List of course IDs to filter by
98
- include: Additional data ('submission', 'assignment_visibility', etc.)
99
100
Returns:
101
Paginated list of Assignment objects
102
"""
103
104
def get_user_assignments(self, course, **kwargs) -> PaginatedList[Assignment]:
105
"""
106
Get assignments for the user in a specific course.
107
108
Parameters:
109
- course: Course object or course ID
110
- include: Additional data to include
111
112
Returns:
113
Paginated list of Assignment objects
114
"""
115
```
116
117
### File and Folder Management
118
119
Manage user's personal files and folder organization.
120
121
```python { .api }
122
def get_files(self, **kwargs) -> PaginatedList[File]:
123
"""
124
List files for the user.
125
126
Parameters:
127
- content_types: Filter by content type
128
- exclude_content_types: Exclude specific content types
129
- search_term: Search term to filter files
130
- include: Additional data ('user', 'usage_rights')
131
- only: Filter by file type ('names', 'folders')
132
- sort: Sort files by field ('name', 'size', 'created_at', 'updated_at')
133
- order: Sort order ('asc', 'desc')
134
135
Returns:
136
Paginated list of File objects
137
"""
138
139
def get_folders(self, **kwargs) -> PaginatedList[Folder]:
140
"""
141
List folders for the user.
142
143
Parameters:
144
- sort: Sort folders by field
145
- order: Sort order
146
147
Returns:
148
Paginated list of Folder objects
149
"""
150
151
def create_folder(self, name: str, **kwargs) -> Folder:
152
"""
153
Create a folder in user's files.
154
155
Parameters:
156
- name: Folder name
157
- parent_folder_id: Parent folder ID (optional)
158
- locked: Whether folder is locked
159
- hidden: Whether folder is hidden
160
- position: Position in folder list
161
162
Returns:
163
Folder object
164
"""
165
166
def get_file(self, file_id, **kwargs) -> File:
167
"""Get a specific file by ID."""
168
169
def upload_file(self, file_path: str, **kwargs) -> File:
170
"""
171
Upload a file to user's files.
172
173
Parameters:
174
- file_path: Path to file to upload
175
- name: Custom name for the file
176
- parent_folder_id: Folder to upload to
177
178
Returns:
179
File object
180
"""
181
```
182
183
### Communication Channels
184
185
Manage user's communication preferences and channels.
186
187
```python { .api }
188
def get_communication_channels(self, **kwargs) -> PaginatedList[CommunicationChannel]:
189
"""
190
List communication channels for the user.
191
192
Returns:
193
Paginated list of CommunicationChannel objects (email, SMS, etc.)
194
"""
195
196
def create_communication_channel(self, communication_channel: dict, **kwargs) -> CommunicationChannel:
197
"""
198
Create a communication channel.
199
200
Parameters:
201
- communication_channel: Dictionary with channel attributes:
202
- address: Email address or phone number
203
- type: Channel type ('email', 'sms')
204
- token: Verification token (for SMS)
205
206
Returns:
207
CommunicationChannel object
208
"""
209
```
210
211
### Calendar and Events
212
213
Access user's calendar events and scheduling information.
214
215
```python { .api }
216
def get_calendar_events_for_user(self, **kwargs) -> PaginatedList[CalendarEvent]:
217
"""
218
Get calendar events for the user.
219
220
Parameters:
221
- type: Filter by event type ('event', 'assignment')
222
- start_date: Start date for filtering events
223
- end_date: End date for filtering events
224
- undated: Include undated events
225
- all_events: Include events from all contexts
226
- context_codes: Filter by specific contexts
227
228
Returns:
229
Paginated list of CalendarEvent objects
230
"""
231
```
232
233
### Observing Relationships
234
235
Manage observer relationships (parent-student connections).
236
237
```python { .api }
238
def add_observee(self, observee, **kwargs) -> User:
239
"""
240
Add a user as an observee (for observer accounts).
241
242
Parameters:
243
- observee: User object or user ID to observe
244
- root_account_id: Root account for the relationship
245
246
Returns:
247
User object of the observee
248
"""
249
250
def get_observees(self, **kwargs) -> PaginatedList[User]:
251
"""
252
List users being observed by this user.
253
254
Parameters:
255
- include: Additional data ('avatar_url', etc.)
256
257
Returns:
258
Paginated list of User objects being observed
259
"""
260
261
def remove_observee(self, observee, **kwargs) -> User:
262
"""
263
Remove an observee relationship.
264
265
Parameters:
266
- observee: User object or user ID to stop observing
267
268
Returns:
269
User object of the removed observee
270
"""
271
272
def get_observers(self, **kwargs) -> PaginatedList[User]:
273
"""
274
List users observing this user.
275
276
Returns:
277
Paginated list of User objects (observers)
278
"""
279
```
280
281
### Content Migration
282
283
Manage user's content migrations and imports.
284
285
```python { .api }
286
def create_content_migration(self, migration_type: str, **kwargs) -> ContentMigration:
287
"""
288
Create a content migration for the user.
289
290
Parameters:
291
- migration_type: Type of migration ('zip_file_importer', 'course_copy_importer', etc.)
292
- pre_attachment: File attachment for migration
293
- settings: Migration-specific settings
294
295
Returns:
296
ContentMigration object
297
"""
298
299
def get_content_migrations(self, **kwargs) -> PaginatedList[ContentMigration]:
300
"""List content migrations for the user."""
301
```
302
303
### Analytics and Activity
304
305
Access user activity data and analytics information.
306
307
```python { .api }
308
def get_page_views(self, **kwargs) -> PaginatedList[PageView]:
309
"""
310
Get page view data for the user.
311
312
Parameters:
313
- start_time: Start date for page views
314
- end_time: End date for page views
315
316
Returns:
317
Paginated list of PageView objects
318
"""
319
320
def get_authentication_events(self, **kwargs) -> PaginatedList[AuthenticationEvent]:
321
"""
322
Get authentication events for the user.
323
324
Parameters:
325
- start_time: Start date for events
326
- end_time: End date for events
327
328
Returns:
329
Paginated list of AuthenticationEvent objects
330
"""
331
```
332
333
### ePortfolios
334
335
Manage user's ePortfolios.
336
337
```python { .api }
338
def get_eportfolios(self, **kwargs) -> PaginatedList[EPortfolio]:
339
"""List ePortfolios for the user."""
340
341
def moderate_all_eportfolios(self, **kwargs) -> dict:
342
"""Moderate all ePortfolios for the user (admin function)."""
343
```
344
345
### Usage Rights and Content Licensing
346
347
Manage usage rights for user's content.
348
349
```python { .api }
350
def set_usage_rights(self, file_ids: list, usage_rights: dict, **kwargs) -> UsageRights:
351
"""
352
Set usage rights for files.
353
354
Parameters:
355
- file_ids: List of file IDs
356
- usage_rights: Dictionary with usage rights information:
357
- use_justification: Justification for use
358
- legal_copyright: Copyright information
359
- license: License type
360
361
Returns:
362
UsageRights object
363
"""
364
365
def remove_usage_rights(self, file_ids: list, **kwargs) -> UsageRights:
366
"""
367
Remove usage rights from files.
368
369
Parameters:
370
- file_ids: List of file IDs to remove rights from
371
372
Returns:
373
UsageRights object
374
"""
375
```
376
377
## CurrentUser Class
378
379
Extended functionality for the currently authenticated user.
380
381
```python { .api }
382
class CurrentUser(User):
383
def get_bookmarks(self, **kwargs) -> PaginatedList[Bookmark]:
384
"""List bookmarks for the current user."""
385
386
def create_bookmark(self, **kwargs) -> Bookmark:
387
"""
388
Create a bookmark.
389
390
Parameters:
391
- name: Bookmark name
392
- url: Bookmark URL
393
- position: Position in bookmark list
394
- data: Additional bookmark data
395
396
Returns:
397
Bookmark object
398
"""
399
400
def get_graded_submissions(self, **kwargs) -> PaginatedList[Submission]:
401
"""Get graded submissions for the current user."""
402
403
def list_user_logins(self, **kwargs) -> PaginatedList[Login]:
404
"""List login methods for the current user."""
405
406
def edit_user_login(self, login_id, **kwargs) -> Login:
407
"""Edit a login method for the current user."""
408
```
409
410
## Usage Examples
411
412
### User Profile Management
413
414
```python
415
from canvasapi import Canvas
416
417
canvas = Canvas("https://canvas.example.com", "your-token")
418
user = canvas.get_user(12345)
419
420
# Get and update user profile
421
profile = user.get_profile()
422
print(f"User: {profile['name']} ({profile['primary_email']})")
423
424
# Update user information
425
updated_user = user.edit(
426
name="John Smith",
427
short_name="John",
428
email="john.smith@example.com",
429
bio="Computer Science student interested in AI and machine learning."
430
)
431
```
432
433
### Course and Assignment Access
434
435
```python
436
# Get all courses for a user
437
courses = user.get_courses(
438
enrollment_state='active',
439
include=['needs_grading_count', 'total_scores']
440
)
441
442
for course in courses:
443
print(f"Course: {course.name}")
444
445
# Get assignments for this course
446
assignments = user.get_user_assignments(course)
447
for assignment in assignments:
448
print(f" Assignment: {assignment.name} (Due: {assignment.due_at})")
449
450
# Get missing submissions
451
missing = user.get_missing_submissions(include=['course'])
452
for assignment in missing:
453
print(f"Missing: {assignment.name} in {assignment.course['name']}")
454
```
455
456
### File Management
457
458
```python
459
# Get user's files
460
files = user.get_files(
461
search_term="assignment",
462
sort="created_at",
463
order="desc"
464
)
465
466
for file in files:
467
print(f"File: {file.display_name} ({file.size} bytes)")
468
469
# Create a folder and upload a file
470
folder = user.create_folder("My Assignments")
471
new_file = user.upload_file(
472
"/path/to/assignment.pdf",
473
parent_folder_id=folder.id
474
)
475
```
476
477
### Observer Relationships
478
479
```python
480
# For observer accounts - add a student to observe
481
observer = canvas.get_user(observer_id)
482
student = canvas.get_user(student_id)
483
484
# Add observing relationship
485
observer.add_observee(student)
486
487
# Get all students being observed
488
observees = observer.get_observees()
489
for student in observees:
490
print(f"Observing: {student.name}")
491
492
# Get the student's courses
493
courses = student.get_courses(enrollment_state='active')
494
for course in courses:
495
print(f" Course: {course.name}")
496
```
497
498
### Communication Channels
499
500
```python
501
# Get current communication channels
502
channels = user.get_communication_channels()
503
for channel in channels:
504
print(f"Channel: {channel.address} ({channel.type})")
505
506
# Add a new email address
507
new_channel = user.create_communication_channel({
508
'address': 'alternate@example.com',
509
'type': 'email'
510
})
511
```