GPT Actions library - Canvas LMS

Jul 17, 2024
Open in Github

This particular GPT Action provides an overview of how to connect to Canvas (infrastructure.canvas.com), a widely used LMS tool for course material, grading and general education purposes.

Value: Users can now leverage ChatGPT's natural language capability to connect directly to Canvas

Example Use Cases:

  • Query content from LMS
  • Build quizzes
  • Create new modules
  • Understand topics from assigned courses

Before you get started, make sure you go through the following steps in your application environment:

gptactions_canvaslms_approvedintegrations.png

Once you've created a Custom GPT, copy the text below in the Instructions panel. Have questions? Check out Getting Started Example to see how this step works in more detail.

**Context** : You are a helpful friendly university level course helper designed to search across canvas courses to help students and educators, this GPT is intended to help students and teachers understand course material, take quiz's and tests from information stored in canvas.  


**Instructions**
When asked to perform a task, use the available actions via the canvas.infrastructure.com API


You should be professional and verbose with answers, provide clear pedagogical experience for users. 


Offer assistance with tasks around summarizing course material, understanding module and quiz information. 


Ask for clarification when needed to ensure accuracy and completeness in fulfilling user requests. It should also respect user privacy and handle all data securely.


If a user uploads a file, help the user analyze the file before callin the canvas API.

Once you've created a Custom GPT, copy the text below in the Actions panel. Have questions? Check out Getting Started Example to see how this step works in more detail.

openapi: 3.1.0
info:
  title: Canvas LMS API
  description: >
    This is the API of the Canvas LMS, providing access to various resources such as accounts, courses, users,
    assignments, quizzes, files, and more.
  version: 1.0.0
servers:
  - url: https://canvas.instructure.com
    description: Canvas LMS Production Server
paths:
  /api/v1/accounts:
    get:
      summary: List accounts
      operationId: listAccounts
      responses:
        "200":
          description: A paginated list of accounts
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Account"
  /api/v1/accounts/{account_id}:
    get:
      summary: Get a single account
      operationId: getAccount
      parameters:
        - name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Account details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Account"
  /api/v1/courses:
    get:
      summary: List courses
      operationId: listCourses
      responses:
        "200":
          description: A paginated list of courses
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Course"
  /api/v1/courses/{course_id}:
    get:
      summary: Get a single course
      operationId: getCourse
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Course details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Course"
  /api/v1/courses/{course_id}/assignments:
    get:
      summary: List assignments
      operationId: listAssignments
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: A paginated list of assignments
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Assignment"
  /api/v1/courses/{course_id}/assignments/{assignment_id}:
    get:
      summary: Get a single assignment
      operationId: getAssignment
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
        - name: assignment_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Assignment details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Assignment"
  /api/v1/courses/{course_id}/quizzes:
    get:
      summary: List quizzes
      operationId: listQuizzes
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: A paginated list of quizzes
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Quiz"
  /api/v1/courses/{course_id}/quizzes/{quiz_id}:
    get:
      summary: Get a single quiz
      operationId: getQuiz
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
        - name: quiz_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Quiz details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Quiz"
  /api/v1/courses/{course_id}/students/{student_id}/grades:
     get:
       summary: List grades for a student
       operationId: listGrades
       parameters:
         - name: course_id
           in: path
           required: true
           schema:
             type: integer
         - name: student_id
           in: path
           required: true
           schema:
             type: integer
       responses:
         '200':
           description: A list of grades for the student
           content:
             application/json:
               schema:
                 type: array
                 items:
                   $ref: '#/components/schemas/Grade'
  /api/v1/courses/{course_id}/students/{student_id}/grades/{grade_id}:
    get:
      summary: Get a single grade
      operationId: getGrade
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
        - name: student_id
          in: path
          required: true
          schema:
            type: integer
        - name: grade_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Grade details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Grade'
  /api/v1/courses/{course_id}/syllabus:
    get:
      summary: Get course syllabus
      operationId: getSyllabus
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Syllabus details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Syllabus'
  /api/v1/courses/{course_id}/modules:
    get:
      summary: List modules
      operationId: listModules
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: A list of modules in the course
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Module'
  /api/v1/courses/{course_id}/modules/{module_id}:
    get:
      summary: Get a single module
      operationId: getModule
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
        - name: module_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Module details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Module'
components:
  schemas:
    Account:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        workflow_state:
          type: string
    Course:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        account_id:
          type: integer
        start_at:
          type: string
          format: date-time
        end_at:
          type: string
          format: date-time
    Assignment:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        description:
          type: string
        due_at:
          type: string
          format: date-time
        points_possible:
          type: number
    Quiz:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
        description:
          type: string
        due_at:
          type: string
          format: date-time
        points_possible:
          type: number
    Grade:
      type: object
      properties:
        id:
          type: integer
        student_id:
          type: integer
        course_id:
          type: integer
        assignment_id:
          type: integer
        score:
          type: number
        grade:
          type: string
    Syllabus:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        account_id:
          type: integer
        start_at:
          type: string
          format: date-time
        end_at:
          type: string
          format: date-time
        syllabus_body:
          type: string
        syllabus_url:
          type: string
    Module:
     type: object
     properties:
       id:
         type: integer
       name:
         type: string
       position:
         type: integer
       unlock_at:
         type: string
         format: date-time
       require_sequential_progress:
         type: boolean
       state:
         type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
security:
  - bearerAuth: []

Note : this schema above does not contain all possible API endpoints, be sure to edit the schema to produce the appropriate actions from canvas API documentation

Below are instructions on setting up authentication with this 3rd party application. Have questions? Check out Getting Started Example to see how this step works in more detail.

Before you set up authentication in ChatGPT, please take the following steps in the application. Our sample integration below is utilizing a secret key, which is an easier method for testing. In production, it is more common to establish an OAuth connection to ensure permissions are respected from ChatGPT to Canvas, ensuring users the appropriate access.

  1. Canvas accounts : The first step is to ensure the canvas environment has users assigned to the appropriate role (student / teacher) with any access to appropriate courses
  2. For testing purposes or service level account access create an approved integration access token as seen below
  • Under Account -> Settings -> Approved Integrations

gptactions_canvaslms_settings.png

  • Create new Access Token

gptactions_canvaslms_integrationslist.png

  • Provide purpose and expiration

gptactions_canvaslms_tokencreate.png

  • Copy the new Token to use in the GPT Action (the token will not be accessible once you leave the page - ensure proper token management access is maintained to prevent unauthorzied access from another application.

In ChatGPT, click on "Authentication" and choose "API Key". Enter in the information below. API Key provides general access to the Canvas environment based on the users permissions that created the API key, to follow permission models in Canvas use the OAuth method described below.

  • API Key: Use the token from above
  • Auth Type: Bearer

gptactions_canvaslms_auth.png

OAuth Connection

If you want to implement OAuth, follow the guide here : https://canvas.instructure.com/doc/api/file.oauth.html - specific instructions can vary depending on the Canvas implementation.

Parameters for GPT Configuration

  • Client ID - obtained from site owner
  • Client Secret - obtained from site owner
  • Authorization URL - : https://< canvas-install-url >/login/oauth2/auth?client_id=XXX&response_type=code&redirect_uri=https://example.com/oauth_complete&state=YYY&scope=< value_1 >%20< value_2 >%20< value_n >
  • Token URL : https://< canvas-install-url> /login/oauth2/token

Once you've set up authentication in ChatGPT, follow the steps below in the application to test the Action.

  • You will see a list of available actions from the API schema for Canvas, you can test the endpoints from the GPT builder to ensure Canvas can be reached. Once you verified connection make sure to save the GPT and share it witht the appropriate user base.
  • Note: if you are using OAuth, you will need to set up the callback URL from ChatGPT in the Canvas app
  • Schema calls the wrong project or dataset: If ChatGPT calls the wrong project or dataset, consider updating your instructions to make it more explicit either (a) which project / dataset should be called or (b) to require the user provide those exact details before it runs the query

Are there integrations that you’d like us to prioritize? Are there errors in our integrations? File a PR or issue in our github, and we’ll take a look.