hurah/canvas-api

A set of classes that helps with communicating with the Instructure Canvas API.

v1.0.21 2025-06-11 08:29 UTC

README

Latest Stable Version License CircleCI Build

This library is a PHP SDK for the Instructure Canvas API, designed to simplify communication with Canvas by providing statically typed classes for most API endpoints. It supports both collection and single entity operations. The SDK is still in development but is already being used in small production environments.

Features

  • Statically typed classes: Provides typed classes for most API endpoints.
  • Collections and entities: Easily handle both collections and single entities in a clean object-oriented manner implementing php's Iterator and ArrayAccess interfaces.
  • Centralized communication: All communication goes through an instance of the Canvas object.
  • Symfony Console Commands: Includes commands for manual communication with the API, offering examples, excellent documentation and testing tools.

Installation

Install the package via Composer:

composer require hurah/canvas-api

Usage

Basic Setup

Create an instance of the Canvas object and authenticate with your API credentials:

use Hurah\CanvasApi\Canvas;

$canvas = new Canvas('your-api-url', 'your-access-token');

Fetching Data

Example: fetch a collection

use Hurah\CanvasApi\Canvas;

$oCourseCollection = $canvas->getCourses();
foreach ($oCourseCollection as $oCourse) {
    echo $oCourse->getName();
}

Example: Single Entity

$oCourse = $canvas->getCourse(123);
echo $course->getName();

Example: Create a new Course

$oCourse = new Course();
$oCourse->setName('Some name');
$oCourse->setDescription('Some description');
$oCourse->setSomeOtherProperty('...')
$oCourse = $canvas->createCourse($oCourse);

// The same object is returned containing the course
// id and other default properties.
$oCourse->getId() 

Contributing

Contributions and feedback are welcome! Please keep in mind that this software is in beta and comes as is. Use it at your own risk.

  1. Fork the repository.
  2. Create your feature branch: git checkout -b feature/my-new-feature.
  3. Commit your changes: git commit -m 'Add some feature'.
  4. Push to the branch: git push origin feature/my-new-feature.
  5. Open a pull request.

Links

Author

Anton Boutkam - Teacher Software Development at ROC Amstelland

CicleCI build status

CircleCI

  • v1.0.21 initialized frozenAttributes in Assignment, was breaking unit testing.
  • v1.0.20 upgraded various dependencies
  • v1.0.18 improved README.md
  • v1.0.17 removed Account part due to insufficient privileges on my Canvas account.
  • v1.0.16 added Assignments, AssignmentGroups, CourseCommands, CourseSubmissionCommands, PageCommands, QuizQuestionCommands
  • v1.0.15 bugfix Added missing properties to Assignment endpoint
  • v1.0.13 bugfix Made setters nullable
  • v1.0.12 added Lots of endpoints
  • v1.0.11 added Canvas::getUserCourses(int $iCanvasId):CourseCollection
  • v1.0.10 added QuizQuestionGetCommand, QuizQuestionListCommand
  • v1.0.9 added QuizQuestion
  • v1.0.8 updated QuizQuestion
  • v1.0.7 updated QuizQuestionGroup
  • v1.0.6 updated QuizQuestionGroup
  • v1.0.5 updated Quiz
  • v1.0.3 added Quiz