Documentation

Account extends AbstractBaseApi
in package

Account Class

Represents an account in the Canvas LMS. Accounts are organizational units that contain courses, sub-accounts, users, and other Canvas resources. This class provides methods to create, update, find, and manage accounts and their hierarchical relationships.

Usage:

// Finding an account by ID
$account = Account::find(1);

// Creating a new sub-account
$accountData = [
    'name' => 'Mathematics Department',
    'sisAccountId' => 'MATH_DEPT',
    'parentAccountId' => 1
];
$account = Account::create($accountData);

// Updating an existing account
$account->name = 'Mathematics and Statistics Department';
$account->save();

// Getting sub-accounts (two approaches)
$subAccounts = $account->subAccounts();  // Instance method
$subAccounts = Account::fetchSubAccounts(1); // Static method

// Getting account settings
$settings = $account->getSettings();

// Fetching manageable accounts
$manageableAccounts = Account::getManageableAccounts();

Table of Contents

Properties

$courseCount  : int|null
The number of courses directly under the account
$defaultGroupStorageQuotaMb  : int|null
The storage quota for a group in the account in megabytes
$defaultStorageQuotaMb  : int|null
The storage quota for the account in megabytes
$defaultTimeZone  : string|null
The default time zone of the account
$defaultUserStorageQuotaMb  : int|null
The storage quota for a user in the account in megabytes
$id  : int|null
The ID of the Account object
$integrationId  : string|null
The account's identifier in the Student Information System (alternative field)
$ltiGuid  : string|null
The account's identifier that is sent as context_id in LTI launches
$name  : string|null
The display name of the account
$parentAccountId  : int|null
The account's parent ID, or null if this is the root account
$rootAccountId  : int|null
The ID of the root account, or null if this is the root account
$settings  : array<string, mixed>|null
Account settings
$sisAccountId  : string|null
The account's identifier in the Student Information System
$sisImportId  : int|null
The id of the SIS import if created through SIS
$subAccountCount  : int|null
The number of sub-accounts directly under the account
$uuid  : string|null
The UUID of the account
$workflowState  : string|null
The state of the account. Can be 'active' or 'deleted'
$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
calendarEvents()  : array<string|int, CalendarEvent>
Get calendar events for this account
courses()  : array<int, Course>
Get active courses in this account
create()  : self
Create a new account
createCalendarEvent()  : CalendarEvent
Create a calendar event for this account
createRubric()  : Rubric
Create a rubric for this account
createSharedBrandConfig()  : SharedBrandConfig
Create a shared brand config for this account
delete()  : self
Delete the account (only sub-accounts can be deleted)
deleteSharedBrandConfig()  : SharedBrandConfig
Delete a shared brand config
fetchSubAccounts()  : array<int, self>
Fetch sub-accounts for a given account
find()  : self
Find an account by ID
findRubric()  : Rubric
Find a rubric by ID in this account
get()  : array<string|int, static>
Get first page of results
getBrandVariables()  : array<string, mixed>
Get brand variables for this account's domain
getCourseAccounts()  : array<int, self>
Get accounts that the current user can view through their admin course enrollments
getCourseCreationAccounts()  : array<int, self>
Get accounts where the current user has permission to create courses
getHelpLinks()  : array<string, mixed>|null
Get help links for this account
getId()  : int|null
Get account ID getter
getManageableAccounts()  : array<int, self>
Get accounts where the current user has permission to create or manage courses
getName()  : string|null
Get account name
getPermissions()  : array<string, bool>
Get permissions for the calling user and this account
getRootAccount()  : self
Get the root account
getSettings()  : array<string, mixed>
Get account settings
getSisAccountId()  : string|null
Get SIS account ID
getTermsOfService()  : array<string, mixed>|null
Get the terms of service for this account
isRootAccount()  : bool
Check if this is a root account
paginate()  : PaginationResult
Get paginated results with metadata
parentAccount()  : self|null
Get the parent account
rubrics()  : array<int, Rubric>
Get rubrics for this account
save()  : self
Save the current account instance
setApiClient()  : void
Set the API client
setId()  : self
Set account ID
setName()  : self
Set account name
setSisAccountId()  : self
Set SIS account ID
subAccounts()  : array<int, self>
Get sub-accounts of this account
update()  : self
Update an account
updateSettings()  : self
Update account settings
updateSharedBrandConfig()  : SharedBrandConfig
Update a shared brand config for this account
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

Properties

$courseCount

The number of courses directly under the account

public int|null $courseCount = null

$defaultGroupStorageQuotaMb

The storage quota for a group in the account in megabytes

public int|null $defaultGroupStorageQuotaMb = null

$defaultStorageQuotaMb

The storage quota for the account in megabytes

public int|null $defaultStorageQuotaMb = null

$defaultTimeZone

The default time zone of the account

public string|null $defaultTimeZone = null

$defaultUserStorageQuotaMb

The storage quota for a user in the account in megabytes

public int|null $defaultUserStorageQuotaMb = null

$id

The ID of the Account object

public int|null $id = null

$integrationId

The account's identifier in the Student Information System (alternative field)

public string|null $integrationId = null

$ltiGuid

The account's identifier that is sent as context_id in LTI launches

public string|null $ltiGuid = null

$name

The display name of the account

public string|null $name = null

$parentAccountId

The account's parent ID, or null if this is the root account

public int|null $parentAccountId = null

$rootAccountId

The ID of the root account, or null if this is the root account

public int|null $rootAccountId = null

$settings

Account settings

public array<string, mixed>|null $settings = null

$sisAccountId

The account's identifier in the Student Information System

public string|null $sisAccountId = null

$sisImportId

The id of the SIS import if created through SIS

public int|null $sisImportId = null

$subAccountCount

The number of sub-accounts directly under the account

public int|null $subAccountCount = null

$uuid

The UUID of the account

public string|null $uuid = null

$workflowState

The state of the account. Can be 'active' or 'deleted'

public string|null $workflowState = null

$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>

calendarEvents()

Get calendar events for this account

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

Query parameters

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

courses()

Get active courses in this account

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

Query parameters

Tags
throws
CanvasApiException
Return values
array<int, Course>

create()

Create a new account

public static create(array<string, mixed>|CreateAccountDTO $data[, int|null $parentAccountId = null ]) : self
Parameters
$data : array<string, mixed>|CreateAccountDTO

Account data

$parentAccountId : int|null = null

Parent account ID (if creating sub-account)

Tags
throws
CanvasApiException
Return values
self

createSharedBrandConfig()

Create a shared brand config for this account

public createSharedBrandConfig(array<string, mixed>|CreateSharedBrandConfigDTO $data) : SharedBrandConfig

Creates a new shared brand configuration that can be reused across multiple accounts. The config is associated with this account.

Parameters
$data : array<string, mixed>|CreateSharedBrandConfigDTO

Config data

Tags
throws
CanvasApiException

If the API request fails

example
$account = Account::find(1);
$sharedConfig = $account->createSharedBrandConfig([
    'name' => 'Spring 2024 Theme',
    'brand_config_md5' => 'a1f113321fa024e7a14cb0948597a2a4'
]);
Return values
SharedBrandConfig

The created shared brand config

delete()

Delete the account (only sub-accounts can be deleted)

public delete() : self
Tags
throws
CanvasApiException
Return values
self

deleteSharedBrandConfig()

Delete a shared brand config

public deleteSharedBrandConfig(int $id) : SharedBrandConfig

Deletes a shared brand configuration. Note that the Canvas API uses a different endpoint pattern for deletion (no account_id in path).

Parameters
$id : int

The ID of the shared brand config to delete

Tags
throws
CanvasApiException

If the API request fails

example
$account = Account::find(1);
$deleted = $account->deleteSharedBrandConfig(987);
Return values
SharedBrandConfig

The deleted shared brand config

fetchSubAccounts()

Fetch sub-accounts for a given account

public static fetchSubAccounts(int $accountId[, array<string, mixed> $params = [] ]) : array<int, self>

Static method to fetch sub-accounts without requiring an Account instance. Provides direct access to the sub-accounts endpoint.

Parameters
$accountId : int

The ID of the parent account

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

Query parameters (e.g., 'recursive' => true)

Tags
throws
CanvasApiException
Return values
array<int, self>

Array of Account objects

find()

Find an account by ID

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

Account ID or SIS ID

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

Additional query parameters

Tags
throws
CanvasApiException
Return values
self

findRubric()

Find a rubric by ID in this account

public findRubric(int $rubricId[, array<string, mixed> $params = [] ]) : Rubric
Parameters
$rubricId : int

The rubric ID

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

Query parameters

Tags
throws
CanvasApiException
Return values
Rubric

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>

getBrandVariables()

Get brand variables for this account's domain

public getBrandVariables() : array<string, mixed>

Retrieves the brand configuration variables used by this account. This includes colors, fonts, logos, and other branding elements.

Tags
throws
CanvasApiException

If the API request fails

example
$account = Account::find(1);
$brandVars = $account->getBrandVariables();
echo $brandVars['primary_color'];
Return values
array<string, mixed>

The brand configuration variables

getCourseAccounts()

Get accounts that the current user can view through their admin course enrollments

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

Query parameters

Tags
throws
CanvasApiException
Return values
array<int, self>

getCourseCreationAccounts()

Get accounts where the current user has permission to create courses

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

Query parameters

Tags
throws
CanvasApiException
Return values
array<int, self>

Get help links for this account

public getHelpLinks() : array<string, mixed>|null
Tags
throws
CanvasApiException
Return values
array<string, mixed>|null

getId()

Get account ID getter

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

getManageableAccounts()

Get accounts where the current user has permission to create or manage courses

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

Query parameters

Tags
throws
CanvasApiException
Return values
array<int, self>

getName()

Get account name

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

getPermissions()

Get permissions for the calling user and this account

public getPermissions([array<int, string> $permissions = [] ]) : array<string, bool>
Parameters
$permissions : array<int, string> = []

List of permissions to check

Tags
throws
CanvasApiException
Return values
array<string, bool>

getRootAccount()

Get the root account

public static getRootAccount() : self
Tags
throws
CanvasApiException
Return values
self

getSettings()

Get account settings

public getSettings() : array<string, mixed>
Tags
throws
CanvasApiException
Return values
array<string, mixed>

getSisAccountId()

Get SIS account ID

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

getTermsOfService()

Get the terms of service for this account

public getTermsOfService() : array<string, mixed>|null
Tags
throws
CanvasApiException
Return values
array<string, mixed>|null

isRootAccount()

Check if this is a root account

public isRootAccount() : bool
Return values
bool

parentAccount()

Get the parent account

public parentAccount() : self|null
Tags
throws
CanvasApiException
Return values
self|null

rubrics()

Get rubrics for this account

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

Query parameters

Tags
throws
CanvasApiException
Return values
array<int, Rubric>

setId()

Set account ID

public setId(int $id) : self
Parameters
$id : int
Return values
self

setName()

Set account name

public setName(string $name) : self
Parameters
$name : string
Return values
self

setSisAccountId()

Set SIS account ID

public setSisAccountId(string|null $sisAccountId) : self
Parameters
$sisAccountId : string|null
Return values
self

subAccounts()

Get sub-accounts of this account

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

Query parameters

Tags
throws
CanvasApiException
Return values
array<int, self>

updateSettings()

Update account settings

public updateSettings(array<string, mixed> $settings) : self
Parameters
$settings : array<string, mixed>

Settings to update

Tags
throws
CanvasApiException
Return values
self

updateSharedBrandConfig()

Update a shared brand config for this account

public updateSharedBrandConfig(int $id, array<string, mixed>|UpdateSharedBrandConfigDTO $data) : SharedBrandConfig

Updates an existing shared brand configuration associated with this account.

Parameters
$id : int

The ID of the shared brand config to update

$data : array<string, mixed>|UpdateSharedBrandConfigDTO

The update data

Tags
throws
CanvasApiException

If the API request fails

example
$account = Account::find(1);
$updated = $account->updateSharedBrandConfig(987, [
    'name' => 'Updated Theme Name'
]);
Return values
SharedBrandConfig

The updated shared brand config

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