Documentation

Bookmark extends AbstractBaseApi
in package

Canvas LMS Bookmarks API

The Bookmarks API allows users to create and manage bookmarks for various Canvas resources including courses, groups, users, and other Canvas entities. Bookmarks are user-specific and always operate in the context of the current user.

Tags
see
https://canvas.instructure.com/doc/api/bookmarks.html

Table of Contents

Properties

$data  : string|null
$id  : int|null
$name  : string|null
$position  : int|null
$url  : string|null
$methodAliases  : array<string, array<string|int, string>>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
BaseApi constructor.
all()  : array<string|int, self>
Get all pages of results
create()  : self
Create a new bookmark
delete()  : self
Delete the bookmark
find()  : static
Find a bookmark by ID
get()  : array<string|int, self>
Fetch all bookmarks (alias for get)
overrideApiClient()  : void
Set an API client for this class only, leaving other resources on the shared default.
paginate()  : PaginationResult
Get paginated results with metadata
resetApiClients()  : void
Clear the shared default client and all per-class overrides.
save()  : self
Save the bookmark (create or update)
setApiClient()  : void
Set the shared default API client used by ALL resource classes.
stream()  : Generator<int, static>
Stream all items across all pages one at a time.
update()  : self
Update a bookmark
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
getAliasMap()  : array<string, string>
Build a flat alias-to-method lookup from $methodAliases.
getApiClient()  : HttpClientInterface
Get the API client, initializing if necessary
getApiPropertyName()  : string
Get the API property name for this resource
getEndpoint()  : string
Get the API endpoint
getPaginatedResponse()  : PaginatedResponse
Helper method to get paginated response from API endpoint
hydrate()  : void
Assign API response data to properties with type coercion.
parseJsonResponse()  : array<string|int, mixed>
Parse JSON response from API safely handling StreamInterface
populate()  : void
Populate the object with new data
toDtoArray()  : array<string|int, mixed>
Convert the object to an array
validateContext()  : void
Validate a context type path segment against an allowlist.

Properties

$position

public int|null $position = null

$methodAliases

Define method aliases

protected static array<string, array<string|int, string>> $methodAliases = ['get' => ['fetch', 'list'], 'all' => ['fetchAllPages', 'getAll', 'fetchAll'], 'paginate' => ['getPaginated', 'withPagination'], '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, self>
Parameters
$params : array<string, mixed> = []

Query parameters

Return values
array<string|int, self>

delete()

Delete the bookmark

public delete() : self
Return values
self

find()

Find a bookmark by ID

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

Bookmark ID

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

Optional query parameters

Return values
static

get()

Fetch all bookmarks (alias for get)

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

Query parameters

Return values
array<string|int, self>

paginate()

Get paginated results with metadata

public static paginate([array<string, mixed> $params = [] ]) : PaginationResult
Parameters
$params : array<string, mixed> = []

Query parameters

Return values
PaginationResult

resetApiClients()

Clear the shared default client and all per-class overrides.

public static resetApiClients() : void

save()

Save the bookmark (create or update)

public save() : self
Return values
self

setApiClient()

Set the shared default API client used by ALL resource classes.

public static setApiClient(HttpClientInterface $apiClient) : void

Calling this on any resource (e.g. Course::setApiClient()) replaces the client for every resource, because relationship methods cross class boundaries ($course->enrollments() calls Enrollment internally). Use overrideApiClient() to scope a client to a single class, and resetApiClients() in test teardown to avoid state leaking.

Parameters
$apiClient : HttpClientInterface

stream()

Stream all items across all pages one at a time.

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

Unlike all(), only one page of raw data is held in memory at a time, making this safe for very large datasets (e.g. tens of thousands of enrollments):

foreach (User::stream(['per_page' => 100]) as $user) {
    processUser($user);
}
Parameters
$params : array<string|int, mixed> = []

Query parameters for the request

Tags
throws
CanvasApiException
Return values
Generator<int, static>

update()

Update a bookmark

public static update(int $id, array<string, mixed>|UpdateBookmarkDTO $data) : self
Parameters
$id : int

Bookmark ID

$data : array<string, mixed>|UpdateBookmarkDTO

Update data

Return values
self

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>

getAliasMap()

Build a flat alias-to-method lookup from $methodAliases.

protected static getAliasMap() : array<string, string>
Return values
array<string, string>

getApiPropertyName()

Get the API property name for this resource

protected static getApiPropertyName() : string
Return values
string

getEndpoint()

Get the API endpoint

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

hydrate()

Assign API response data to properties with type coercion.

protected hydrate(array<string|int, mixed> $data) : void

Shared by the constructor and populate() so objects keep the same type guarantees after save()/update() round-trips as on creation.

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

parseJsonResponse()

Parse JSON response from API safely handling StreamInterface

protected static parseJsonResponse(ResponseInterface $response) : array<string|int, mixed>
Parameters
$response : ResponseInterface
Return values
array<string|int, mixed>

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>

validateContext()

Validate a context type path segment against an allowlist.

protected static validateContext(string|null $contextType, array<int, string> $allowed) : void

Context types are interpolated into URL paths; validating against the contexts Canvas actually supports prevents crafted values from injecting extra path segments or query parameters.

Parameters
$contextType : string|null

The context type (plural, e.g. 'courses'); null is ignored

$allowed : array<int, string>

Allowed context types

Tags
throws
CanvasApiException

If the context type is not allowed

On this page

Search results