Documentation

User extends AbstractBaseApi
in package

User Class

Represents a user in the Canvas LMS. This class provides methods to create, update, and find users from the Canvas LMS system. It utilizes Data Transfer Objects (DTOs) for handling user creation and updates.

The User class supports Canvas's "self" pattern, allowing users to access their own data without knowing their user ID. The Canvas API documentation states: "the :user_id parameter can always be replaced with self if the requesting user is asking for his/her own information."

Usage Examples:

// Current user operations (using the self pattern)
$currentUser = User::self();
$profile = $currentUser->profile();
$courses = $currentUser->courses();
$todos = $currentUser->getTodo();        // Short alias
$todoItems = $currentUser->getTodoItems(); // Full method name
$groups = $currentUser->groups();

// Creating a new user (admin operation)
$userData = [
    'username' => 'john_doe',
    'email' => 'john.doe@example.com',
    // ... other user data ...
];
$user = User::create($userData);

// Updating an existing user (admin operation)
$updatedData = [
    'email' => 'new_john.doe@example.com',
    // ... other updated data ...
];
$updatedUser = User::update(123, $updatedData); // where 123 is the user ID

// Finding a user by ID (admin operation)
$user = User::find(123);

// Get first page of users (memory efficient)
$users = User::get();
$users = User::get(['per_page' => 100]); // Custom page size

// Get ALL users from all pages (⚠️ CAUTION: Could be thousands!)
$allUsers = User::all(); // Be very careful with large institutions

// Get paginated results with metadata (recommended for user lists)
$paginated = User::paginate(['per_page' => 100]);
echo "Showing {$paginated->getPerPage()} of {$paginated->getTotalCount()} users";

// Process in batches for large datasets
$page = 1;
do {
    $batch = User::paginate(['page' => $page++, 'per_page' => 500]);
    // Process batch...
} while ($batch->hasNextPage());

Table of Contents

Properties

$avatarState  : string|null
Optional: If avatars are enabled and caller is admin, this field can be requested and will contain the current state of the user's avatar.
$avatarUrl  : string|null
If avatars are enabled, this field will be included and contain a url to retrieve the user's avatar.
$bio  : string|null
Optional: The user's bio.
$canUpdateName  : bool|null
Optional: This field is only returned in certain API calls, and will return a boolean value indicating whether or not the user can update their name.
$effectiveLocale  : string|null
The user's effective locale.
$email  : string|null
Optional: This field can be requested with certain API calls, and will return the users primary email address.
$enrollments  : array<string|int, mixed>|null
Optional: This field can be requested with certain API calls, and will return a list of the users active enrollments. See the List enrollments API for more details about the format of these records.
$firstName  : string
The first name of the user.
$id  : int
The ID of the user.
$integrationId  : string|null
The integration_id associated with the user. This field is only included if the user came from a SIS import and has permissions to view SIS information.
$lastLogin  : string|null
Optional: This field is only returned in certain API calls, and will return a timestamp representing the last time the user logged in to canvas.
$lastName  : string
The last name of the user.
$locale  : string|null
Optional: This field can be requested with certain API calls, and will return the users locale in RFC 5646 format.
$loginId  : string
The unique login id for the user. This is what the user uses to log in to Canvas.
$name  : string
The name of the user.
$shortName  : string
A short name the user has selected, for use in conversations or other less formal places through the site.
$sisImportId  : int|null
The id of the SIS import. This field is only included if the user came from a SIS import and has permissions to manage SIS information.
$sisUserId  : string|null
The SIS ID associated with the user. This field is only included if the user came from a SIS import and has permissions to view SIS information.
$sortableName  : string
The name of the user that it should be used for sorting groups of users, such as in the gradebook.
$timeZone  : string|null
Optional: This field is only returned in certain API calls, and will return the IANA time zone name of the user's preferred timezone.
$apiClient  : HttpClientInterface
$methodAliases  : array<string|int, mixed>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
BaseApi constructor.
all()  : array<string|int, static>
Get all pages of results
clearAllCourseNicknames()  : bool
Clear all course nicknames for the user
contentMigration()  : ContentMigration
Get a specific content migration for this user
contentMigrations()  : array<string|int, ContentMigration>
Get content migrations for this user
courseAnalytics()  : array<string, array<string, mixed>>
Get analytics data for this user in a specific course
courseNickname()  : CourseNickname|null
Get course nickname for a specific course
courses()  : array<string|int, Course>
Get courses for this user
create()  : self
Create a new User instance.
createCalendarEvent()  : CalendarEvent
Create a calendar event for this user
createContentMigration()  : ContentMigration
Create a content migration for this user
deleteCustomData()  : bool
Delete custom data for the user
enrollments()  : array<string|int, Enrollment>
Get enrollments for this user (relationship method alias with parameter support)
featureFlag()  : FeatureFlag
Get a specific feature flag for this user.
featureFlags()  : array<int, FeatureFlag>
Get all feature flags for this user.
fetchSelf()  : self
Fetch the current authenticated user's full data from Canvas.
files()  : array<string|int, File>
Get files for this user
find()  : self
Find a single user by ID.
get()  : array<string|int, static>
Get first page of results
getActiveEnrollments()  : array<string|int, Enrollment>
Get active enrollments for this user
getActivityStream()  : array<string|int, ActivityStreamItem>
Get the user's activity stream
getActivityStreamSummary()  : array<string|int, ActivityStreamSummary>
Get activity stream summary
getAvatarOptions()  : array<string|int, Avatar>
Get avatar options
getAvatarState()  : string|null
getAvatarUrl()  : string|null
getBio()  : string|null
getCalendarEvents()  : array<string|int, CalendarEvent>
Get calendar events for this user
getCanUpdateName()  : bool|null
getCourseNicknames()  : array<string|int, CourseNickname>
Get all course nicknames for the user
getCustomData()  : array<string, mixed>
Get custom data for the user
getEffectiveLocale()  : string|null
getEmail()  : string|null
getEnrollments()  : array<string|int, mixed>|null
getEnrollmentsData()  : array<string|int, mixed>|null
Get the user's enrollment data array (legacy method - uses embedded data)
getEnrollmentsInCourse()  : array<string|int, Enrollment>
Get enrollments for this user in a specific course
getFirstName()  : string
getId()  : int
getIntegrationId()  : string|null
getLastLogin()  : string|null
getLastName()  : string
getLocale()  : string|null
getLoginId()  : string
getMissingSubmissions()  : array<string|int, Assignment>
Get missing submissions
getName()  : string
getPageViews()  : array<string|int, PageView>
Get page views for the user
getPandataEventsToken()  : array<string, mixed>
Get pandata events token
getShortName()  : string
getSisImportId()  : int|null
getSisUserId()  : string|null
getSortableName()  : string
getStudentEnrollments()  : array<string|int, Enrollment>
Get student enrollments for this user
getTeacherEnrollments()  : array<string|int, Enrollment>
Get teacher enrollments for this user
getTimeZone()  : string|null
getTodo()  : array<string|int, TodoItem>
Get todo items for the user (alias for getTodoItems)
getTodoItems()  : array<string|int, TodoItem>
Get TODO items
getUpcomingEvents()  : array<string|int, UpcomingEvent>
Get upcoming events
groups()  : array<string|int, Group>
Get groups for this user
hideAllStreamItems()  : bool
Hide all stream items
hideStreamItem()  : bool
Hide a stream item
importCommonCartridge()  : ContentMigration
Import content from a Common Cartridge file
importZipFile()  : ContentMigration
Import content from a ZIP file
isEnrolledInCourse()  : bool
Check if this user is enrolled in a specific course
isStudentInCourse()  : bool
Check if this user is a student in a specific course
isTeacherInCourse()  : bool
Check if this user is a teacher in a specific course
logins()  : array<string|int, Login>
Get logins (pseudonyms) for this user
mergeInto()  : bool
Merge current user into another one
paginate()  : PaginationResult
Get paginated results with metadata
profile()  : Profile
Get user profile
removeCourseNickname()  : bool
Remove course nickname for a specific course
removeFeatureFlag()  : bool
Remove a feature flag for this user.
save()  : self
Save the user to the Canvas LMS.
self()  : self
Get an instance representing the current authenticated user.
selfRegister()  : self
Self-register a new user
setApiClient()  : void
Set the API client
setAvatarState()  : void
setAvatarUrl()  : void
setBio()  : void
setCanUpdateName()  : void
setCourseNickname()  : CourseNickname
Set course nickname for a specific course
setCustomData()  : array<string, mixed>
Store custom data for the user
setEffectiveLocale()  : void
setEmail()  : void
setEnrollments()  : void
setFeatureFlag()  : FeatureFlag
Update a feature flag for this user.
setFirstName()  : void
setId()  : void
setIntegrationId()  : void
setLastLogin()  : void
setLastName()  : void
setLocale()  : void
setLoginId()  : void
setName()  : void
setShortName()  : void
setSisImportId()  : void
setSisUserId()  : void
setSortableName()  : void
setTimeZone()  : void
split()  : array<string|int, self>
Split a merged user
terminateAllSessions()  : bool
Terminate all sessions for the user
update()  : self
Update an existing user.
uploadFile()  : File
Upload a file to the user's personal files
castValue()  : DateTime|mixed
Cast a value to the correct type
checkApiClient()  : void
Check if the API client is set, if not, instantiate a new one
convertPaginatedResponseToModels()  : array<string|int, static>
Helper method to convert paginated response data to model instances
createConfiguredHttpClient()  : HttpClient
Create an HttpClient with configured middleware
createPaginationResult()  : PaginationResult
Helper method to create PaginationResult from paginated response
getEndpoint()  : string
Get the API endpoint for this resource
getPaginatedResponse()  : PaginatedResponse
Helper method to get paginated response from API endpoint
populate()  : void
Populate the object with new data
toDtoArray()  : array<string|int, mixed>
Convert the object to an array
createFromDTO()  : self
Create a User from a CreateUserDTO.
updateFromDTO()  : self
Update a user from a UpdateUserDTO.

Properties

$avatarState

Optional: If avatars are enabled and caller is admin, this field can be requested and will contain the current state of the user's avatar.

public string|null $avatarState

$avatarUrl

If avatars are enabled, this field will be included and contain a url to retrieve the user's avatar.

public string|null $avatarUrl

$bio

Optional: The user's bio.

public string|null $bio

$canUpdateName

Optional: This field is only returned in certain API calls, and will return a boolean value indicating whether or not the user can update their name.

public bool|null $canUpdateName = null

$effectiveLocale

The user's effective locale.

public string|null $effectiveLocale = null

$email

Optional: This field can be requested with certain API calls, and will return the users primary email address.

public string|null $email

$enrollments

Optional: This field can be requested with certain API calls, and will return a list of the users active enrollments. See the List enrollments API for more details about the format of these records.

public array<string|int, mixed>|null $enrollments

$firstName

The first name of the user.

public string $firstName

$id

The ID of the user.

public int $id

$integrationId

The integration_id associated with the user. This field is only included if the user came from a SIS import and has permissions to view SIS information.

public string|null $integrationId

$lastLogin

Optional: This field is only returned in certain API calls, and will return a timestamp representing the last time the user logged in to canvas.

public string|null $lastLogin

$lastName

The last name of the user.

public string $lastName

$locale

Optional: This field can be requested with certain API calls, and will return the users locale in RFC 5646 format.

public string|null $locale

$loginId

The unique login id for the user. This is what the user uses to log in to Canvas.

public string $loginId

$name

The name of the user.

public string $name

$shortName

A short name the user has selected, for use in conversations or other less formal places through the site.

public string $shortName

$sisImportId

The id of the SIS import. This field is only included if the user came from a SIS import and has permissions to manage SIS information.

public int|null $sisImportId

$sisUserId

The SIS ID associated with the user. This field is only included if the user came from a SIS import and has permissions to view SIS information.

public string|null $sisUserId

$sortableName

The name of the user that it should be used for sorting groups of users, such as in the gradebook.

public string $sortableName

$timeZone

Optional: This field is only returned in certain API calls, and will return the IANA time zone name of the user's preferred timezone.

public string|null $timeZone

$methodAliases

Define method aliases

protected static array<string|int, mixed> $methodAliases = ['get' => ['fetch', 'list', 'fetchAll'], 'all' => ['fetchAllPages', 'getAll'], 'paginate' => ['getPaginated', 'withPagination', 'fetchPage'], 'find' => ['one', 'getOne']]

Methods

__callStatic()

Magic method to handle function aliases

public static __callStatic(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
$name : string
$arguments : array<string|int, mixed>
Tags
throws
InvalidArgumentException

__construct()

BaseApi constructor.

public __construct(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>

all()

Get all pages of results

public static all([array<string, mixed> $params = [] ]) : array<string|int, static>
Parameters
$params : array<string, mixed> = []

Query parameters

Return values
array<string|int, static>

clearAllCourseNicknames()

Clear all course nicknames for the user

public clearAllCourseNicknames() : bool

Remove all course nicknames set by the user, reverting all courses to their original names.

Tags
throws
CanvasApiException
Return values
bool

True if successful

contentMigrations()

Get content migrations for this user

public contentMigrations([array<string, mixed> $params = [] ]) : array<string|int, ContentMigration>
Parameters
$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, ContentMigration>

courseAnalytics()

Get analytics data for this user in a specific course

public courseAnalytics(int $courseId[, array<string, mixed> $params = [] ]) : array<string, array<string, mixed>>
Parameters
$courseId : int

The course ID

$params : array<string, mixed> = []

Optional query parameters

Tags
throws
CanvasApiException
Return values
array<string, array<string, mixed>>

Analytics data for the user in the course

courseNickname()

Get course nickname for a specific course

public courseNickname(int $courseId) : CourseNickname|null

Returns the nickname for the specified course, or null if no nickname is set.

Parameters
$courseId : int

Course ID to get nickname for

Tags
throws
CanvasApiException
Return values
CourseNickname|null

The course nickname or null

courses()

Get courses for this user

public courses([array<string, mixed> $params = [] ]) : array<string|int, Course>
Parameters
$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, Course>

create()

Create a new User instance.

public static create(array<string|int, mixed>|CreateUserDTO $userData) : self
Parameters
$userData : array<string|int, mixed>|CreateUserDTO
Tags
throws
Exception
Return values
self

deleteCustomData()

Delete custom data for the user

public deleteCustomData(string $namespace[, string|null $scope = null ]) : bool

Delete arbitrary user data that was previously stored. The namespace parameter is required to identify the data set. The scope parameter is optional and must match what was used when storing.

Parameters
$namespace : string

Namespace to delete data from

$scope : string|null = null

Optional scope that was used when storing

Tags
throws
CanvasApiException
Return values
bool

True if successful

enrollments()

Get enrollments for this user (relationship method alias with parameter support)

public enrollments([array<string|int, mixed> $params = [] ]) : array<string|int, Enrollment>

This method provides a clean, explicit way to access user enrollments across all courses without conflicts with Canvas API data structure. Supports all Canvas API enrollment parameters for filtering.

Parameters
$params : array<string|int, mixed> = []

Query parameters for filtering enrollments:

  • type[]: Filter by enrollment type (e.g., ['StudentEnrollment', 'TeacherEnrollment'])
  • role[]: Filter by enrollment role
  • state[]: Filter by enrollment state (e.g., ['active', 'invited', 'completed'])
  • include[]: Include additional data (e.g., ['course', 'avatar_url'])
Tags
example
$user = User::find(456);

// Get all enrollments for this user
$enrollments = $user->enrollments();

// Get active enrollments only
$activeEnrollments = $user->enrollments([
    'state[]' => ['active']
]);

// Get student enrollments only
$studentEnrollments = $user->enrollments([
    'type[]' => ['StudentEnrollment']
]);

// Get enrollments with course data included
$enrollmentsWithCourses = $user->enrollments([
    'include[]' => ['course']
]);
throws
CanvasApiException

If the user ID is not set or API request fails

Return values
array<string|int, Enrollment>

Array of Enrollment objects

featureFlag()

Get a specific feature flag for this user.

public featureFlag(string $featureName) : FeatureFlag
Parameters
$featureName : string

The symbolic name of the feature

Tags
throws
CanvasApiException
Return values
FeatureFlag

featureFlags()

Get all feature flags for this user.

public featureFlags([array<string, mixed> $params = [] ]) : array<int, FeatureFlag>
Parameters
$params : array<string, mixed> = []

Optional query parameters

Tags
throws
CanvasApiException
Return values
array<int, FeatureFlag>

Array of FeatureFlag objects

fetchSelf()

Fetch the current authenticated user's full data from Canvas.

public static fetchSelf() : self

This method retrieves complete user information for the authenticated user, including all properties like id, name, email, avatar_url, etc.

Unlike self() which returns an empty User instance for use with methods that support the "self" pattern, this method actually fetches the user data from the Canvas API.

Example usage:

// Get complete user data for the authenticated user
$currentUser = User::fetchSelf();
echo $currentUser->id;       // 12345
echo $currentUser->name;     // "John Doe"
echo $currentUser->email;    // "john@example.com"

// You can then use all User methods with the fetched data
$courses = $currentUser->courses();
$profile = $currentUser->profile();
Tags
throws
CanvasApiException

If the API request fails

Return values
self

A fully populated User instance with all user data

files()

Get files for this user

public files([array<string, mixed> $params = [] ]) : array<string|int, File>
Parameters
$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, File>

find()

Find a single user by ID.

public static find(int $id[, array<string|int, mixed> $params = [] ]) : self
Parameters
$id : int
$params : array<string|int, mixed> = []

Optional query parameters

Tags
throws
CanvasApiException
Return values
self

get()

Get first page of results

public static get([array<string, mixed> $params = [] ]) : array<string|int, static>
Parameters
$params : array<string, mixed> = []

Query parameters

Return values
array<string|int, static>

getActiveEnrollments()

Get active enrollments for this user

public getActiveEnrollments([array<string|int, mixed> $params = [] ]) : array<string|int, Enrollment>

Convenience method to get only active enrollments across all courses.

Parameters
$params : array<string|int, mixed> = []

Additional query parameters

Tags
throws
CanvasApiException

If user ID is not set or API request fails

Return values
array<string|int, Enrollment>

Array of active Enrollment objects

getActivityStream()

Get the user's activity stream

public getActivityStream([array<string, mixed> $params = [] ]) : array<string|int, ActivityStreamItem>

Returns the current user's global activity stream, paginated. Use 'self' as the user ID to get the current authenticated user's stream.

Parameters
$params : array<string, mixed> = []

Optional parameters

Tags
throws
CanvasApiException
Return values
array<string|int, ActivityStreamItem>

getActivityStreamSummary()

Get activity stream summary

public getActivityStreamSummary() : array<string|int, ActivityStreamSummary>

Returns a summary of the current user's global activity stream. Use 'self' as the user ID to get the current authenticated user's summary.

Tags
throws
CanvasApiException
Return values
array<string|int, ActivityStreamSummary>

getAvatarOptions()

Get avatar options

public getAvatarOptions() : array<string|int, Avatar>

Retrieve the possible user avatar options that can be set for the user. This includes uploaded files, Gravatar, and social media avatars.

Tags
throws
CanvasApiException
Return values
array<string|int, Avatar>

Array of Avatar objects

getAvatarState()

public getAvatarState() : string|null
Return values
string|null

getAvatarUrl()

public getAvatarUrl() : string|null
Return values
string|null

getBio()

public getBio() : string|null
Return values
string|null

getCalendarEvents()

Get calendar events for this user

public getCalendarEvents([array<string, mixed> $params = [] ]) : array<string|int, CalendarEvent>
Parameters
$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, CalendarEvent>

getCanUpdateName()

public getCanUpdateName() : bool|null
Return values
bool|null

getCourseNicknames()

Get all course nicknames for the user

public getCourseNicknames() : array<string|int, CourseNickname>

Returns a list of all course nicknames set by the user.

Tags
throws
CanvasApiException
Return values
array<string|int, CourseNickname>

Array of CourseNickname objects

getCustomData()

Get custom data for the user

public getCustomData(string $namespace[, string|null $scope = null ]) : array<string, mixed>

Retrieve arbitrary user data that was previously stored. The namespace parameter is required to identify the data set. The scope parameter is optional and must match what was used when storing.

Parameters
$namespace : string

Namespace to retrieve data from

$scope : string|null = null

Optional scope that was used when storing

Tags
throws
CanvasApiException
Return values
array<string, mixed>

The stored data

getEffectiveLocale()

public getEffectiveLocale() : string|null
Return values
string|null

getEmail()

public getEmail() : string|null
Return values
string|null

getEnrollments()

public getEnrollments() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

getEnrollmentsData()

Get the user's enrollment data array (legacy method - uses embedded data)

public getEnrollmentsData() : array<string|int, mixed>|null

This returns the raw enrollments array that may be embedded in the user object from certain Canvas API calls. For fetching current enrollments from the API, use enrollments() instead.

Return values
array<string|int, mixed>|null

Raw enrollments data array or null

getEnrollmentsInCourse()

Get enrollments for this user in a specific course

public getEnrollmentsInCourse(int $courseId[, array<string|int, mixed> $params = [] ]) : array<string|int, Enrollment>

Returns only the enrollments for this user in the specified course. This is useful for checking a user's role(s) in a particular course.

Parameters
$courseId : int

The course ID to filter enrollments by

$params : array<string|int, mixed> = []

Additional query parameters

Tags
throws
CanvasApiException

If user ID is not set or API request fails

Return values
array<string|int, Enrollment>

Array of Enrollment objects for the specified course

getFirstName()

public getFirstName() : string
Return values
string

getId()

public getId() : int
Return values
int

getIntegrationId()

public getIntegrationId() : string|null
Return values
string|null

getLastLogin()

public getLastLogin() : string|null
Return values
string|null

getLastName()

public getLastName() : string
Return values
string

getLocale()

public getLocale() : string|null
Return values
string|null

getLoginId()

public getLoginId() : string
Return values
string

getMissingSubmissions()

Get missing submissions

public getMissingSubmissions([array<string, mixed> $params = [] ]) : array<string|int, Assignment>

Returns a paginated list of assignments for which the student has not yet created a submission. The user sending the request must either be the student, or must have permission to view the student's grades.

Parameters
$params : array<string, mixed> = []

Optional parameters:

  • filter[]: Array of assignment IDs to filter by
  • filter[course_ids][]: Array of course IDs to filter by
  • include[]: Array of additional fields to include: ['planner_overrides', 'course']
  • filter[submittable_types][]: Only return assignments that the user can submit online. Excludes assignments with no submission type.
Tags
throws
CanvasApiException
Return values
array<string|int, Assignment>

getName()

public getName() : string
Return values
string

getPageViews()

Get page views for the user

public getPageViews([array<string, mixed> $params = [] ]) : array<string|int, PageView>

Return a paginated list of the user's page view history in Canvas. Page views provide detailed tracking of user interactions within Canvas.

Parameters
$params : array<string, mixed> = []

Optional parameters:

  • start_time: DateTime to start the search from (ISO 8601 format)
  • end_time: DateTime to end the search at (ISO 8601 format)
Tags
throws
CanvasApiException
Return values
array<string|int, PageView>

Array of PageView objects

getPandataEventsToken()

Get pandata events token

public getPandataEventsToken() : array<string, mixed>

Return the user's pandata events token. This token is used for analytics and tracking purposes.

Tags
throws
CanvasApiException
Return values
array<string, mixed>

The pandata events token data

getShortName()

public getShortName() : string
Return values
string

getSisImportId()

public getSisImportId() : int|null
Return values
int|null

getSisUserId()

public getSisUserId() : string|null
Return values
string|null

getSortableName()

public getSortableName() : string
Return values
string

getStudentEnrollments()

Get student enrollments for this user

public getStudentEnrollments([array<string|int, mixed> $params = [] ]) : array<string|int, Enrollment>

Convenience method to get only student enrollments across all courses.

Parameters
$params : array<string|int, mixed> = []

Additional query parameters

Tags
throws
CanvasApiException

If user ID is not set or API request fails

Return values
array<string|int, Enrollment>

Array of student Enrollment objects

getTeacherEnrollments()

Get teacher enrollments for this user

public getTeacherEnrollments([array<string|int, mixed> $params = [] ]) : array<string|int, Enrollment>

Convenience method to get only teacher enrollments across all courses.

Parameters
$params : array<string|int, mixed> = []

Additional query parameters

Tags
throws
CanvasApiException

If user ID is not set or API request fails

Return values
array<string|int, Enrollment>

Array of teacher Enrollment objects

getTimeZone()

public getTimeZone() : string|null
Return values
string|null

getTodo()

Get todo items for the user (alias for getTodoItems)

public getTodo([array<string, mixed> $params = [] ]) : array<string|int, TodoItem>

Convenience method that provides a shorter alias for getTodoItems(). Returns the list of todo items for this user.

Parameters
$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, TodoItem>

getTodoItems()

Get TODO items

public getTodoItems([array<string, mixed> $params = [] ]) : array<string|int, TodoItem>

Get a paginated list of the current user's list of todo items, as seen on the user dashboard.

Parameters
$params : array<string, mixed> = []

Optional parameters:

  • include[]: 'ungraded_quizzes' to include ungraded quizzes
Tags
throws
CanvasApiException
Return values
array<string|int, TodoItem>

groups()

Get groups for this user

public groups([array<string, mixed> $params = [] ]) : array<string|int, Group>

Note: This method supports the 'self' identifier for the current user when called on an instance returned by User::self().

Parameters
$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, Group>

hideAllStreamItems()

Hide all stream items

public hideAllStreamItems() : bool

Hide all stream items for the user. Use 'self' as the user ID for the current authenticated user.

Tags
throws
CanvasApiException
Return values
bool

True if successful

hideStreamItem()

Hide a stream item

public hideStreamItem(int $streamItemId) : bool

Hide the given stream item for the user. Use 'self' as the user ID for the current authenticated user.

Parameters
$streamItemId : int

The ID of the stream item to hide

Tags
throws
CanvasApiException
Return values
bool

True if successful

importCommonCartridge()

Import content from a Common Cartridge file

public importCommonCartridge(string $filePath[, array<string, mixed> $options = [] ]) : ContentMigration
Parameters
$filePath : string

Path to the .imscc file

$options : array<string, mixed> = []

Additional options

Tags
throws
CanvasApiException
Return values
ContentMigration

importZipFile()

Import content from a ZIP file

public importZipFile(string $filePath[, array<string, mixed> $options = [] ]) : ContentMigration
Parameters
$filePath : string

Path to the .zip file

$options : array<string, mixed> = []

Additional options

Tags
throws
CanvasApiException
Return values
ContentMigration

isEnrolledInCourse()

Check if this user is enrolled in a specific course

public isEnrolledInCourse(int $courseId[, string|null $enrollmentType = null ]) : bool
Parameters
$courseId : int

The course ID to check enrollment in

$enrollmentType : string|null = null

Optional: specific enrollment type to check for

Tags
throws
CanvasApiException

If user ID is not set or API request fails

Return values
bool

True if user is enrolled in the course (with optional type filter)

isStudentInCourse()

Check if this user is a student in a specific course

public isStudentInCourse(int $courseId) : bool
Parameters
$courseId : int

The course ID to check

Tags
throws
CanvasApiException

If user ID is not set or API request fails

Return values
bool

True if user has a student enrollment in the course

isTeacherInCourse()

Check if this user is a teacher in a specific course

public isTeacherInCourse(int $courseId) : bool
Parameters
$courseId : int

The course ID to check

Tags
throws
CanvasApiException

If user ID is not set or API request fails

Return values
bool

True if user has a teacher enrollment in the course

logins()

Get logins (pseudonyms) for this user

public logins([array<string, mixed> $params = [] ]) : array<string|int, Login>

Note: This method supports the 'self' identifier for the current user when called on an instance returned by User::self().

Parameters
$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, Login>

mergeInto()

Merge current user into another one

public mergeInto(int $destinationUserId) : bool
Parameters
$destinationUserId : int

The ID of the user to merge into

Tags
throws
Exception
Return values
bool

profile()

Get user profile

public profile() : Profile

Returns the full profile information for the user. This includes extended information beyond the basic User object.

Tags
throws
CanvasApiException
Return values
Profile

The user's profile

removeCourseNickname()

Remove course nickname for a specific course

public removeCourseNickname(int $courseId) : bool

Remove the nickname for the specified course, reverting to the original course name.

Parameters
$courseId : int

Course ID to remove nickname for

Tags
throws
CanvasApiException
Return values
bool

True if successful

removeFeatureFlag()

Remove a feature flag for this user.

public removeFeatureFlag(string $featureName) : bool
Parameters
$featureName : string

The symbolic name of the feature

Tags
throws
CanvasApiException
Return values
bool

self()

Get an instance representing the current authenticated user.

public static self() : self

This method returns a User instance configured to use Canvas's "self" identifier, allowing access to the current user's data without knowing their user ID.

Note: Only specific Canvas API endpoints support the "self" identifier:

  • Activity stream endpoints (getActivityStream, getActivityStreamSummary, hideStreamItem)
  • Todo and upcoming events (getTodoItems, getUpcomingEvents)
  • Profile and avatar endpoints (getProfile, getAvatarOptions)
  • Course nicknames (getCourseNicknames, setCourseNickname, etc.)
  • Groups endpoint (groups() method uses /users/self/groups)

Methods that do NOT support self:

  • File operations (use numeric user ID)
  • Custom data storage
  • Page views
  • Most other endpoints
Tags
example
// Get current user's profile
$currentUser = User::self();
$profile = $currentUser->profile();

// Get current user's todo items
$todos = $currentUser->getTodoItems();

// Get current user's groups
$groups = $currentUser->groups();
Return values
self

A User instance configured for the current authenticated user

selfRegister()

Self-register a new user

public static selfRegister(array<string, mixed> $userData) : self

Self register and return a new user and pseudonym for the account. If self-registration is enabled on the Canvas account, a user can use this endpoint to self register.

Parameters
$userData : array<string, mixed>

User registration data

Tags
throws
CanvasApiException
Return values
self

The newly registered user

setAvatarState()

public setAvatarState(string|null $avatarState) : void
Parameters
$avatarState : string|null

setAvatarUrl()

public setAvatarUrl(string|null $avatarUrl) : void
Parameters
$avatarUrl : string|null

setBio()

public setBio(string|null $bio) : void
Parameters
$bio : string|null

setCanUpdateName()

public setCanUpdateName(bool|null $canUpdateName) : void
Parameters
$canUpdateName : bool|null

setCourseNickname()

Set course nickname for a specific course

public setCourseNickname(int $courseId, string $nickname) : CourseNickname

Set or update the nickname for the specified course.

Parameters
$courseId : int

Course ID to set nickname for

$nickname : string

The nickname to set

Tags
throws
CanvasApiException
Return values
CourseNickname

The updated course nickname

setCustomData()

Store custom data for the user

public setCustomData(string $namespace, array<string, mixed> $data[, string|null $scope = null ]) : array<string, mixed>

Store arbitrary user data. Arbitrary JSON data can be stored as a hash, and a namespace parameter is required to isolate different sets of data. The scope parameter is optional and allows for additional segmentation.

Parameters
$namespace : string

Namespace to store the data under

$data : array<string, mixed>

Arbitrary data to store

$scope : string|null = null

Optional scope for additional data segmentation

Tags
throws
CanvasApiException
Return values
array<string, mixed>

The stored data

setEffectiveLocale()

public setEffectiveLocale(string|null $effectiveLocale) : void
Parameters
$effectiveLocale : string|null

setEmail()

public setEmail(string|null $email) : void
Parameters
$email : string|null

setEnrollments()

public setEnrollments(array<string|int, mixed>|null $enrollments) : void
Parameters
$enrollments : array<string|int, mixed>|null

setFirstName()

public setFirstName(string $firstName) : void
Parameters
$firstName : string

setId()

public setId(int $id) : void
Parameters
$id : int

setIntegrationId()

public setIntegrationId(string|null $integrationId) : void
Parameters
$integrationId : string|null

setLastLogin()

public setLastLogin(string|null $lastLogin) : void
Parameters
$lastLogin : string|null

setLastName()

public setLastName(string $lastName) : void
Parameters
$lastName : string

setLocale()

public setLocale(string|null $locale) : void
Parameters
$locale : string|null

setLoginId()

public setLoginId(string $loginId) : void
Parameters
$loginId : string

setName()

public setName(string $name) : void
Parameters
$name : string

setShortName()

public setShortName(string $shortName) : void
Parameters
$shortName : string

setSisImportId()

public setSisImportId(int|null $sisImportId) : void
Parameters
$sisImportId : int|null

setSisUserId()

public setSisUserId(string|null $sisUserId) : void
Parameters
$sisUserId : string|null

setSortableName()

public setSortableName(string $sortableName) : void
Parameters
$sortableName : string

setTimeZone()

public setTimeZone(string|null $timeZone) : void
Parameters
$timeZone : string|null

split()

Split a merged user

public split() : array<string|int, self>

Split a merged user into separate user accounts. This operation is typically used to reverse a user merge operation.

Tags
throws
CanvasApiException
Return values
array<string|int, self>

Array of User objects created from the split

terminateAllSessions()

Terminate all sessions for the user

public terminateAllSessions() : bool

Terminate all active sessions for the user. This will force the user to log in again on all devices.

Tags
throws
CanvasApiException
Return values
bool

True if successful

update()

Update an existing user.

public static update(int $id, UpdateUserDTO|array<string|int, mixed> $userData) : self
Parameters
$id : int
$userData : UpdateUserDTO|array<string|int, mixed>
Tags
throws
CanvasApiException
throws
Exception
Return values
self

uploadFile()

Upload a file to the user's personal files

public uploadFile(array<string, mixed> $fileData) : File

Uploads a file to the user's personal files area using Canvas's 3-step upload process. The file will be placed in the user's root folder unless a parent_folder_id is specified.

Parameters
$fileData : array<string, mixed>

File upload data with the following possible keys:

  • name: Required. The file name
  • size: File size in bytes (optional if uploading from local file)
  • content_type: MIME type (optional, will be detected if not provided)
  • parent_folder_id: ID of the folder to upload to (optional, defaults to root)
  • file: Path to local file to upload
  • url: URL to download and upload (alternative to 'file')
  • on_duplicate: What to do if file already exists ('overwrite' or 'rename', defaults to 'overwrite')
Tags
throws
CanvasApiException
Return values
File

The uploaded File object

castValue()

Cast a value to the correct type

protected castValue(string $key, mixed $value) : DateTime|mixed
Parameters
$key : string
$value : mixed
Tags
throws
Exception
Return values
DateTime|mixed

checkApiClient()

Check if the API client is set, if not, instantiate a new one

protected static checkApiClient() : void

convertPaginatedResponseToModels()

Helper method to convert paginated response data to model instances

protected static convertPaginatedResponseToModels(PaginatedResponse $paginatedResponse) : array<string|int, static>
Parameters
$paginatedResponse : PaginatedResponse
Return values
array<string|int, static>

getEndpoint()

Get the API endpoint for this resource

protected static getEndpoint() : string
Return values
string

getPaginatedResponse()

Helper method to get paginated response from API endpoint

protected static getPaginatedResponse(string $endpoint[, array<string|int, mixed> $params = [] ]) : PaginatedResponse
Parameters
$endpoint : string

The API endpoint path

$params : array<string|int, mixed> = []

Query parameters for the request

Return values
PaginatedResponse

populate()

Populate the object with new data

protected populate(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>
Tags
throws
Exception

toDtoArray()

Convert the object to an array

protected toDtoArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results