├── sample.env ├── output └── .gitignore ├── src ├── internal │ ├── util.js │ ├── put.js │ ├── post.js │ ├── fetch.js │ ├── del.js │ ├── fetchAll.js │ └── getOptions.js ├── getAccountIds.js ├── getAccounts.js ├── getSelf.js ├── getFile.js ├── getUser.js ├── getOutcome.js ├── getAnalytics.js ├── getGroupsInCourse.js ├── getProgress.js ├── getCoursesByUser.js ├── getDeptIdsInAccount.js ├── getSubaccounts.js ├── getCourseAnalytics.js ├── getGroupDiscussionTopics.js ├── getDiscussionTopic.js ├── getQuizSubmission.js ├── getCustomGradeBookColumns.js ├── getFullDiscussion.js ├── deleteCustomGradebookColumn.js ├── getFullGroupDiscussion.js ├── getGroupDiscussionTopic.js ├── getHistory.js ├── getUserPageViews.js ├── getCourse.js ├── getCourses.js ├── getModules.js ├── getSections.js ├── getUsersInCourse.js ├── createUser.js ├── updateCourse.js ├── createCourse.js ├── getCourseSections.js ├── getUsersInAccount.js ├── getAssignments.js ├── getPlannerItemsByUser.js ├── createGroup.js ├── hideCustomGradebookColumn.js ├── getDiscussionTopics.js ├── getEnrollmentsInCourse.js ├── courseCopy.js ├── getEnrollmentsInSection.js ├── createGroupMembership.js ├── createGroupCategories.js ├── getQuizQuestions.js ├── getRubricsInCourse.js ├── checkProgressStatus.js ├── getQuizSubmissions.js ├── showCustomGradebookColumn.js ├── createUserCourseEnrollment.js ├── createUserSectionEnrollment.js ├── getModuleItems.js ├── batchCopyCourseContent.js ├── deleteSubmissionComment.js ├── copyCourseContent.js ├── getAssignmentSubmissions.js ├── getRubric.js ├── deleteAllCustomGradebookColumns.js ├── getAllCourseSyllabiInAccount.js ├── getSyllabusOfCourse.js ├── getQuizSubmissionEvents.js ├── putStudentNumberInGradeColumn.js ├── createCustomGradebookColumn.js ├── getAllCoursesInAccount.js ├── postAssignmentSubmissionComment.js ├── getAllCoursesInDept.js ├── putStudentNumberInExistingCustomColumn.js ├── hideCustomGradebookColumnsByName.js ├── showCustomGradebookColumnsByName.js ├── putStudentNumbersInGradebook.js ├── downloadFile.js └── index.js ├── .github └── workflows │ └── project.yml ├── package.json ├── LICENSE ├── .gitignore └── README.md /sample.env: -------------------------------------------------------------------------------- 1 | CANVAS_API_TOKEN= 2 | CANVAS_API_DOMAIN=https://{institution}.instructure.com/api/v1 -------------------------------------------------------------------------------- /output/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore -------------------------------------------------------------------------------- /src/internal/util.js: -------------------------------------------------------------------------------- 1 | export default function buildOptions (options) { 2 | if (options) return options.join('&') 3 | else return '' 4 | } 5 | -------------------------------------------------------------------------------- /src/getAccountIds.js: -------------------------------------------------------------------------------- 1 | import getAccounts from './getAccounts.js' 2 | 3 | /** 4 | * Returns all account ids 5 | * @return {Promise} A list of account IDs 6 | */ 7 | 8 | const getAccountIds = async () => { 9 | const accounts = await getAccounts() 10 | const ids = accounts.map(({ id }) => id) 11 | return ids 12 | } 13 | 14 | export default getAccountIds 15 | -------------------------------------------------------------------------------- /src/getAccounts.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Returns all account ids 7 | * @return {Promise} A list of account objects: https://canvas.instructure.com/doc/api/accounts.html#Account 8 | */ 9 | 10 | export default function getAccounts () { 11 | return fetchAll(canvasDomain + `/accounts`) 12 | } 13 | -------------------------------------------------------------------------------- /src/getSelf.js: -------------------------------------------------------------------------------- 1 | import fetch from './internal/fetch.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrieves information about the user 7 | * @return {Promise} A promise that resolves to a User object: https://canvas.instructure.com/doc/api/users.html#User 8 | */ 9 | 10 | export default function getSelf () { 11 | return fetch(canvasDomain + '/users/self') 12 | } 13 | -------------------------------------------------------------------------------- /src/getFile.js: -------------------------------------------------------------------------------- 1 | import fetch from './internal/fetch.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Get file object by fileId 7 | * @param {Number} fileId the file id. 8 | * @return {Promise} A promise that resolves to a File object: https://canvas.instructure.com/doc/api/files.html#File 9 | */ 10 | 11 | export default function getFile (fileId) { 12 | return fetch(canvasDomain + `/files/${fileId}`) 13 | } 14 | -------------------------------------------------------------------------------- /src/internal/put.js: -------------------------------------------------------------------------------- 1 | import nodeFetch from 'node-fetch' 2 | import dotenv from 'dotenv' 3 | 4 | dotenv.config() 5 | 6 | const token = process.env.CANVAS_API_TOKEN 7 | 8 | const putRequest = (url, body) => nodeFetch({ 9 | 'method': 'PUT', 10 | 'uri': url, 11 | 'json': true, 12 | 'form': body, 13 | 'headers': { 14 | 'Authorization': 'Bearer ' + token 15 | } 16 | }).then(response => response) 17 | 18 | export default putRequest 19 | -------------------------------------------------------------------------------- /src/getUser.js: -------------------------------------------------------------------------------- 1 | import fetch from './internal/fetch.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrieves a user by the user ID 7 | * @param {Number} userId user ID. 8 | * @return {Promise} A promise that resolves to a User object: https://canvas.instructure.com/doc/api/users.html#User 9 | */ 10 | 11 | export default function getUser (userId) { 12 | return fetch(canvasDomain + `/users/${userId}/`) 13 | } 14 | -------------------------------------------------------------------------------- /src/getOutcome.js: -------------------------------------------------------------------------------- 1 | import fetch from './internal/fetch.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrieves an outcome 7 | * @param {Number} outcomeId the outcome id. 8 | * @return {Promise} A promise that resolves to an Outcome object: https://canvas.instructure.com/doc/api/outcomes.html 9 | */ 10 | 11 | export default function getOutcome (outcomeId) { 12 | return fetch(canvasDomain + `/outcomes/${outcomeId}`) 13 | } 14 | -------------------------------------------------------------------------------- /src/internal/post.js: -------------------------------------------------------------------------------- 1 | import nodeFetch from 'node-fetch' 2 | import dotenv from 'dotenv' 3 | 4 | dotenv.config() 5 | 6 | const token = process.env.CANVAS_API_TOKEN 7 | 8 | const postRequest = (url, body) => nodeFetch({ 9 | 'method': 'POST', 10 | 'uri': url, 11 | 'json': true, 12 | 'form': body, 13 | 'headers': { 14 | 'Authorization': 'Bearer ' + token 15 | } 16 | }).then(response => response).catch(err => console.log(err)) 17 | 18 | export default postRequest 19 | -------------------------------------------------------------------------------- /src/getAnalytics.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrieves activity analytics for specified account. 7 | * @param {Number} accountId the account id. 8 | * @return {Promise} A promise that resolves to a list of Activity objects 9 | */ 10 | 11 | export default function getAnalytics (accountId) { 12 | return fetchAll(canvasDomain + `/accounts/${accountId}/analytics/current/activity`) 13 | } 14 | -------------------------------------------------------------------------------- /src/getGroupsInCourse.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrives all groups in a course 7 | * @param {Number} courseId the course id. 8 | * @return {Promise} A promise that resolves to an array of group objects 9 | */ 10 | 11 | const getGroupsInCourse = async courseId => { 12 | return fetchAll(canvasDomain + `/courses/${courseId}/groups`) 13 | } 14 | 15 | export default getGroupsInCourse 16 | -------------------------------------------------------------------------------- /src/getProgress.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrieves progress of asynchronous operation. 7 | * @param {Number} id get the progress of id. 8 | * @return {Promise} A promise that resolves to a Progress object: https://canvas.instructure.com/doc/api/progress.html 9 | */ 10 | 11 | export default function getProgress (id) { 12 | return fetchAll(canvasDomain + `/progress/${id}`) 13 | } 14 | -------------------------------------------------------------------------------- /src/getCoursesByUser.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Get all courses a user is enrolled in 7 | * @param {Number} userId the user id. 8 | * @return {Promise} A promise that resolves to an array of Course object: https://canvas.instructure.com/doc/api/courses.html 9 | */ 10 | 11 | export default function getCoursesByUser (userId) { 12 | return fetchAll(canvasDomain + `/users/${userId}/courses`) 13 | } 14 | -------------------------------------------------------------------------------- /src/getDeptIdsInAccount.js: -------------------------------------------------------------------------------- 1 | import getSubaccounts from './getSubaccounts.js' 2 | 3 | /** 4 | * Retrieves all depts in account 5 | * @param {Number} accountId the account id. 6 | * @return {Promise} A promise that resolves to a list of Subaccount objects 7 | */ 8 | 9 | const getDeptIdsInAccount = async accountId => { 10 | const accounts = await getSubaccounts(accountId) 11 | const deptIds = accounts.map(({ id, name }) => ({ id, name })) 12 | return deptIds 13 | } 14 | 15 | export default getDeptIdsInAccount 16 | -------------------------------------------------------------------------------- /src/getSubaccounts.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrieves all subaccounts in an account 7 | * @param {Number} accountId the course id. 8 | * @return {Promise} A promise that resolves to a Account object: https://canvas.instructure.com/doc/api/accounts.html#Account 9 | */ 10 | 11 | export default function getSubaccounts (accountId) { 12 | return fetchAll(canvasDomain + `/accounts/${accountId}/sub_accounts?`) 13 | } 14 | -------------------------------------------------------------------------------- /src/getCourseAnalytics.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrives high-level course analytics 7 | * @param {Number} courseId the course id. 8 | * @return {Promise} A promise that resolves to a User object: https://canvas.instructure.com/doc/api/users.html#User 9 | */ 10 | 11 | export default function getCourseAnalytics (courseId) { 12 | return fetchAll(canvasDomain + `/courses/${courseId}/analytics/student_summaries`) 13 | } 14 | -------------------------------------------------------------------------------- /src/getGroupDiscussionTopics.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrives all discussion topics in group 7 | * @param {Number} groupId the group id. 8 | * @return {Promise} A promise that resolves to a list of Discussion topics 9 | */ 10 | 11 | const getGroupDiscussionTopics = async groupId => { 12 | return fetchAll(canvasDomain + `/groups/${groupId}/discussion_topics`) 13 | } 14 | 15 | export default getGroupDiscussionTopics 16 | -------------------------------------------------------------------------------- /.github/workflows/project.yml: -------------------------------------------------------------------------------- 1 | name: Add issues to LA project 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | 8 | jobs: 9 | add-to-project: 10 | name: Add issue to project 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/add-to-project@v0.3.0 14 | with: 15 | # You can target a repository in a different organization 16 | # to the issue 17 | project-url: https://github.com/orgs/ubc/projects/7 18 | github-token: ${{ secrets.ADD_TO_PROJECT_LA }} 19 | -------------------------------------------------------------------------------- /src/getDiscussionTopic.js: -------------------------------------------------------------------------------- 1 | import fetch from './internal/fetch.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrives a single discussion topic 7 | * @param {Number} courseId the course id. 8 | * @param {Number} topicId the discussion topic id. 9 | * @return {Promise} A promise that resolves to a discussion topic Object 10 | */ 11 | 12 | const getDiscussionTopics = async (courseId, topicId) => { 13 | return fetch(canvasDomain + `/courses/${courseId}/discussion_topics/${topicId}`) 14 | } 15 | 16 | export default getDiscussionTopics 17 | -------------------------------------------------------------------------------- /src/getQuizSubmission.js: -------------------------------------------------------------------------------- 1 | import fetch from './internal/fetch.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrives a single submission 7 | * @param {Number} courseId the course id. 8 | * @param {Number} quizId the quiz id. 9 | * @return {Promise} A promise that resolves to a submission Object 10 | */ 11 | 12 | const getQuizSubmission = async (courseId, quizId, submissionId) => { 13 | return fetch(canvasDomain + `/courses/${courseId}/quizzes/${quizId}/submissions/${submissionId}`) 14 | } 15 | 16 | export default getQuizSubmission 17 | -------------------------------------------------------------------------------- /src/internal/fetch.js: -------------------------------------------------------------------------------- 1 | import nodeFetch from 'node-fetch' 2 | import Bottleneck from 'bottleneck' 3 | import dotenv from 'dotenv' 4 | 5 | dotenv.config() 6 | 7 | const token = process.env.CANVAS_API_TOKEN 8 | 9 | const limiter = new Bottleneck({ 10 | maxConcurrent: 20, 11 | minTime: 100 12 | }) 13 | 14 | const fetch = url => nodeFetch(url, { 15 | method: 'GET', 16 | headers: { 17 | 'Authorization': 'Bearer ' + token 18 | } 19 | }).then(response => response.json()) 20 | 21 | const fetchRateLimited = limiter.wrap(fetch) 22 | 23 | export default fetchRateLimited 24 | -------------------------------------------------------------------------------- /src/getCustomGradeBookColumns.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Get Custom GradeBook Columns 7 | * @param {Number} courseId the course id. 8 | * @return {Promise} A promise that resolves to a CustomColumn object: https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#CustomColumn 9 | */ 10 | 11 | export default function getCustomGradeBookColumns (courseId) { 12 | return fetchAll(canvasDomain + `/courses/${courseId}/custom_gradebook_columns?include_hidden=true`) 13 | } 14 | -------------------------------------------------------------------------------- /src/getFullDiscussion.js: -------------------------------------------------------------------------------- 1 | import fetch from './internal/fetch.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrives all discussion topics in course 7 | * @param {Number} courseId the course id. 8 | * @param {Number} topicId the discussion topic id. 9 | * @return {Promise} A promise that resolves to a discussion topic view object 10 | */ 11 | 12 | const getFullDiscussion = async (courseId, topicId) => { 13 | return fetch(canvasDomain + `/courses/${courseId}/discussion_topics/${topicId}/view`) 14 | } 15 | 16 | export default getFullDiscussion 17 | -------------------------------------------------------------------------------- /src/internal/del.js: -------------------------------------------------------------------------------- 1 | import nodeFetch from 'node-fetch' 2 | 3 | const token = process.env.CANVAS_API_TOKEN 4 | 5 | const deleteRequest = (url, body) => nodeFetch(url, { 6 | method: 'DELETE', 7 | headers: { 8 | 'Authorization': 'Bearer ' + token, 9 | 'Content-Type': 'application/json' // Specify content type for JSON 10 | }, 11 | body: JSON.stringify(body) // Serialize body to JSON 12 | }) 13 | .then(response => response.ok ? response.json() : Promise.reject(response)) 14 | .catch(err => console.error('Request failed:', err)) 15 | 16 | export default deleteRequest 17 | -------------------------------------------------------------------------------- /src/deleteCustomGradebookColumn.js: -------------------------------------------------------------------------------- 1 | import deleteRequest from './internal/del.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Creates course 7 | * @param {Number} courseId the course ID of the target course. 8 | * @return {Promise} A CustomColumn objects: https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#CustomColumn 9 | */ 10 | 11 | export default function deleteCustomGradebookColumn (courseId, gradebookColumnId) { 12 | return deleteRequest(canvasDomain + `/courses/${courseId}/custom_gradebook_columns/${gradebookColumnId}`) 13 | } 14 | -------------------------------------------------------------------------------- /src/getFullGroupDiscussion.js: -------------------------------------------------------------------------------- 1 | import fetch from './internal/fetch.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrives all discussion topics in group 7 | * @param {Number} groupId the group id. 8 | * @param {Number} topicId the discussion topic id. 9 | * @return {Promise} A promise that resolves to a discussion topic view object 10 | */ 11 | 12 | const getFullGroupDiscussion = async (groupId, topicId) => { 13 | return fetch(canvasDomain + `/groups/${groupId}/discussion_topics/${topicId}/view`) 14 | } 15 | 16 | export default getFullGroupDiscussion 17 | -------------------------------------------------------------------------------- /src/getGroupDiscussionTopic.js: -------------------------------------------------------------------------------- 1 | import fetch from './internal/fetch.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrives a single discussion topic from a group 7 | * @param {Number} groupId the group id. 8 | * @param {Number} topicId the discussion topic id. 9 | * @return {Promise} A promise that resolves to a discussion topic Object 10 | */ 11 | 12 | const getGroupDiscussionTopic = async (groupId, topicId) => { 13 | return fetch(canvasDomain + `/groups/${groupId}/discussion_topics/${topicId}`) 14 | } 15 | 16 | export default getGroupDiscussionTopic 17 | -------------------------------------------------------------------------------- /src/getHistory.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Retrives the recent history of the user: https://canvas.instructure.com/doc/api/history.html 7 | * @param {Number} userId the user id. 8 | * @return {Promise} A promise that resolves to an array of history events object: https://canvas.instructure.com/doc/api/history.html#HistoryEntry 9 | */ 10 | 11 | const getHistory = async (userId = 'self') => { 12 | return fetchAll(canvasDomain + `/users/${userId}/history`) 13 | } 14 | 15 | export default getHistory 16 | -------------------------------------------------------------------------------- /src/getUserPageViews.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves all PageViews of a user 8 | * @param {Number} userId get pageviews of user. 9 | * @return {Promise} A promise that resolves to a list of PageView objects: https://canvas.instructure.com/doc/api/users.html#PageView 10 | */ 11 | 12 | export default function getUserPageViews (userId, ...options) { 13 | return fetchAll(canvasDomain + `/users/${userId}/page_views?` + buildOptions(options)) 14 | } 15 | -------------------------------------------------------------------------------- /src/getCourse.js: -------------------------------------------------------------------------------- 1 | import fetch from './internal/fetch.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves course info 8 | * @param {Number} courseId the course id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a Course object: https://canvas.instructure.com/doc/api/courses.html#Course 11 | */ 12 | 13 | export default function getCourse (courseId, ...options) { 14 | return fetch(canvasDomain + `/courses/${courseId}?` + buildOptions(options)) 15 | } 16 | -------------------------------------------------------------------------------- /src/getCourses.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves all courses in a deptId 8 | * @param {Number} deptId the dept id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a Course object: https://canvas.instructure.com/doc/api/courses.html#Course 11 | */ 12 | 13 | export default function getCourses (deptId, ...options) { 14 | return fetchAll(canvasDomain + `/accounts/${deptId}/courses?` + buildOptions(options)) 15 | } 16 | -------------------------------------------------------------------------------- /src/getModules.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves all modules in a course 8 | * @param {Number} courseId the course id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a list of Module objects: https://canvas.instructure.com/doc/api/modules.html 11 | */ 12 | 13 | export default function getModules (courseId, ...options) { 14 | return fetchAll(canvasDomain + `/courses/${courseId}/modules?` + buildOptions(options)) 15 | } 16 | -------------------------------------------------------------------------------- /src/getSections.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves all sections in course 8 | * @param {Number} courseId the course id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a list of Section objects: https://canvas.instructure.com/doc/api/sections.html 11 | */ 12 | 13 | export default function getSections (courseId, ...options) { 14 | return fetchAll(canvasDomain + `/courses/${courseId}/sections?` + buildOptions(options)) 15 | } 16 | -------------------------------------------------------------------------------- /src/getUsersInCourse.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves all users in course 8 | * @param {Number} courseId the course id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a list of User objects: https://canvas.instructure.com/doc/api/users.html#User 11 | */ 12 | 13 | export default function getUsersInCourse (courseId, ...options) { 14 | return fetchAll(canvasDomain + `/courses/${courseId}/users?` + buildOptions(options)) 15 | } 16 | -------------------------------------------------------------------------------- /src/createUser.js: -------------------------------------------------------------------------------- 1 | import postRequest from './internal/post.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Creates group 7 | * @param {Number} accountId the account that the user will be created in. 8 | * @param {Number} body the object that contains the request parameters as indicated here: 9 | * https://canvas.instructure.com/doc/api/users.html#method.users.create 10 | * @return {Promise} A User object: https://canvas.instructure.com/doc/api/users.html#User 11 | */ 12 | 13 | export default function createUser (accountId, body) { 14 | return postRequest(canvasDomain + `/accounts/${accountId}/users`, body) 15 | } 16 | -------------------------------------------------------------------------------- /src/updateCourse.js: -------------------------------------------------------------------------------- 1 | import putRequest from './internal/put.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Update a course 7 | * @param {Number} courseId the course id. 8 | * @param {Object} options the options to pass in body of PUT request: https://canvas.instructure.com/doc/api/courses.html#method.courses.update 9 | * @return {Promise} A promise that resolves to a course metadata response: https://canvas.instructure.com/doc/api/courses.html#method.courses.update 10 | */ 11 | 12 | export default function updateCourse (courseId, options) { 13 | return putRequest(canvasDomain + `/courses/${courseId}`, options) 14 | } 15 | -------------------------------------------------------------------------------- /src/createCourse.js: -------------------------------------------------------------------------------- 1 | import postRequest from './internal/post.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Creates course 7 | * @param {Number} accountId the account ID of the source course. 8 | * @param {Number} body the object that contains the request parameters as indicated here: 9 | * https://canvas.instructure.com/doc/api/courses.html#method.courses.create 10 | * @return {Promise} A Course object: https://canvas.instructure.com/doc/api/courses.html#Course 11 | */ 12 | 13 | export default function createCourse (accountId, body) { 14 | return postRequest(canvasDomain + `/accounts/${accountId}/courses`, body) 15 | } 16 | -------------------------------------------------------------------------------- /src/getCourseSections.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves course info 8 | * @param {Number} courseId the course id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a list of Section object: https://canvas.instructure.com/doc/api/sections.html#method.sections.index 11 | */ 12 | 13 | export default function getCourseSections (courseId, ...options) { 14 | return fetchAll(canvasDomain + `/courses/${courseId}/sections?` + buildOptions(options)) 15 | } 16 | -------------------------------------------------------------------------------- /src/getUsersInAccount.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves all users under an Account 8 | * @param {Number} accountId the account id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a list of User objects: https://canvas.instructure.com/doc/api/users.html#User 11 | */ 12 | 13 | export default function getUsersInAccount (accountId, ...options) { 14 | return fetchAll(canvasDomain + `/accounts/${accountId}/users?` + buildOptions(options)) 15 | } 16 | -------------------------------------------------------------------------------- /src/getAssignments.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves all assignments in a course 8 | * @param {Number} courseId the course id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a list of Assignment objects: https://canvas.instructure.com/doc/api/assignments.html#Assignment 11 | */ 12 | 13 | export default function getAssignments (courseId, ...options) { 14 | return fetchAll(canvasDomain + `/courses/${courseId}/assignments?` + buildOptions(options)) 15 | } 16 | -------------------------------------------------------------------------------- /src/getPlannerItemsByUser.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Get the planner items for a user 8 | * @param {Number} userId the user id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to an array of planner items: https://canvas.instructure.com/doc/api/planner.html#method.planner.index 11 | */ 12 | 13 | export default function getPlannerItemsByUser (userId, ...options) { 14 | return fetchAll(canvasDomain + `/users/${userId}/planner/items?` + buildOptions(options)) 15 | } 16 | -------------------------------------------------------------------------------- /src/createGroup.js: -------------------------------------------------------------------------------- 1 | import postRequest from './internal/post.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Creates group 7 | * @param {Number} groupCategoryId the Group Category ID. 8 | * @param {Number} body the object that contains the request parameters as indicated here: 9 | * https://canvas.instructure.com/doc/api/groups.html#method.groups.create 10 | * @return {Promise} A Group object: https://canvas.instructure.com/doc/api/groups.html#method.groups.create 11 | */ 12 | 13 | export default function createGroup (groupCategoryId, body) { 14 | return postRequest(canvasDomain + `/group_categories/${groupCategoryId}/groups`, body) 15 | } 16 | -------------------------------------------------------------------------------- /src/hideCustomGradebookColumn.js: -------------------------------------------------------------------------------- 1 | import putRequest from './internal/put.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Hide Custom Gradebook Column by Column Id 7 | * @param {Number} courseId the course id. 8 | * @param {Number} columnId the column id. 9 | * @return {Promise} A promise that resolves to a CustomColumn object: https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#CustomColumn 10 | */ 11 | 12 | export default function hideCustomGradebookColumn (courseId, columnId) { 13 | return putRequest(canvasDomain + `/courses/${courseId}/custom_gradebook_columns/${columnId}`, { 14 | 'column[hidden]': true 15 | }) 16 | } 17 | -------------------------------------------------------------------------------- /src/getDiscussionTopics.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrives all discussion topics in course 8 | * @param {Number} courseId the course id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a list of Discussion topics 11 | */ 12 | 13 | const getDiscussionTopics = async (courseId, ...options) => { 14 | return fetchAll( 15 | canvasDomain + 16 | `/courses/${courseId}/discussion_topics?` + 17 | buildOptions(options) 18 | ) 19 | } 20 | 21 | export default getDiscussionTopics 22 | -------------------------------------------------------------------------------- /src/getEnrollmentsInCourse.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves all enrollments in course 8 | * @param {Number} courseId the course id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a list of Enrollment objects: https://canvas.instructure.com/doc/api/enrollments.html#method.enrollments_api.index 11 | */ 12 | 13 | export default function getEnrollmentsInCourse (courseId, ...options) { 14 | return fetchAll(canvasDomain + `/courses/${courseId}/enrollments?` + buildOptions(options)) 15 | } 16 | -------------------------------------------------------------------------------- /src/courseCopy.js: -------------------------------------------------------------------------------- 1 | import postRequest from './internal/post.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Initiates course copy. 7 | * @param {Number} sourceCourseId the course ID of the source course. 8 | * @param {Number} targetCourseId the course ID of the target course. 9 | * @return {Promise} A promise that resolves to a contentMigration object 10 | */ 11 | 12 | function courseCopy (sourceCourseId, targetCourseId) { 13 | return postRequest(canvasDomain + `/courses/${targetCourseId}/content_migrations`, { 14 | 'migration_type': 'course_copy_importer', 15 | 'settings[source_course_id]': `${sourceCourseId}` 16 | }) 17 | } 18 | 19 | export default courseCopy 20 | -------------------------------------------------------------------------------- /src/getEnrollmentsInSection.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves all enrollments in section 8 | * @param {Number} sectionId the section id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a list of Enrollment objects: https://canvas.instructure.com/doc/api/enrollments.html#method.enrollments_api.index 11 | */ 12 | 13 | export default function getEnrollmentsInSection (sectionId, ...options) { 14 | return fetchAll(canvasDomain + `/sections/${sectionId}/enrollments?` + buildOptions(options)) 15 | } 16 | -------------------------------------------------------------------------------- /src/createGroupMembership.js: -------------------------------------------------------------------------------- 1 | import postRequest from './internal/post.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Creates group membership (add user to group) 7 | * @param {Number} groupCategoryId the Group Category ID. 8 | * @param {Number} body the object that contains the request parameters as indicated here: 9 | * https://canvas.instructure.com/doc/api/groups.html#method.group_memberships.create 10 | * @return {Promise} A Group Membership object: https://canvas.instructure.com/doc/api/groups.html#GroupMembership 11 | */ 12 | 13 | export default function createGroupMembership (groupId, body) { 14 | return postRequest(canvasDomain + `/groups/${groupId}/memberships`, body) 15 | } 16 | -------------------------------------------------------------------------------- /src/createGroupCategories.js: -------------------------------------------------------------------------------- 1 | import postRequest from './internal/post.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Creates Group Category 7 | * @param {Number} courseId the course ID of the source course. 8 | * @param {Number} body the object that contains the request parameters as indicated here: 9 | * https://canvas.instructure.com/doc/api/group_categories.html#method.group_categories.create 10 | * @return {Promise} A GroupCategory object: https://canvas.instructure.com/doc/api/group_categories.html#GroupCategory 11 | */ 12 | 13 | export default function createGroupCategory (courseId, body) { 14 | return postRequest(canvasDomain + `/courses/${courseId}/group_categories`, body) 15 | } 16 | -------------------------------------------------------------------------------- /src/getQuizQuestions.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves all questions in a quiz. 8 | * @param {Number} courseId the course id. 9 | * @param {Number} quizId the quiz id. 10 | * @param {Array} options an array of options to include. 11 | * @return {Promise} A promise that resolves to a list of Quiz submission objects: https://canvas.instructure.com/doc/api/submissions.html 12 | */ 13 | 14 | export default function getQuizQuestions (courseId, quizId, ...options) { 15 | return fetchAll(canvasDomain + `/courses/${courseId}/quizzes/${quizId}/questions?` + buildOptions(options)) 16 | } 17 | -------------------------------------------------------------------------------- /src/getRubricsInCourse.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | import getOptions from './internal/getOptions.js' 4 | 5 | const canvasDomain = process.env.CANVAS_API_DOMAIN 6 | 7 | /** 8 | * Retrieves all rubrics in course 9 | * @param {Number} courseId the course id. 10 | * @param {Array} options an array of options to include. 11 | * @return {Promise} A promise that resolves to a list of Rubric objects: https://canvas.instructure.com/doc/api/rubrics.html 12 | */ 13 | 14 | export default function getRubricsInCourse (courseId, ...options) { 15 | return fetchAll(canvasDomain + `/courses/${courseId}/rubrics?` + buildOptions([getOptions.rubric.assessments, options])) 16 | } 17 | -------------------------------------------------------------------------------- /src/checkProgressStatus.js: -------------------------------------------------------------------------------- 1 | import getProgress from './getProgress.js' 2 | 3 | /** 4 | * Returns true if progress of id is complete, false otherwise 5 | * @param {Number} id get the progress of id 6 | * @return {Promise} A promise that resolves to true if progress is complete, false otherwise 7 | */ 8 | 9 | export default function checkProgressStatus (id) { 10 | return new Promise((resolve, reject) => { 11 | getProgress(id) 12 | .then(({ completion, workflow_state }) => { 13 | if (completion === 100) { 14 | resolve(true) 15 | } 16 | if (workflow_state === 'completed') { 17 | resolve(true) 18 | } else resolve(false) 19 | }) 20 | .catch(e => reject(e)) 21 | }) 22 | } 23 | -------------------------------------------------------------------------------- /src/getQuizSubmissions.js: -------------------------------------------------------------------------------- 1 | import buildOptions from './internal/util.js' 2 | 3 | import fetchAll from './internal/fetchAll.js' 4 | 5 | const canvasDomain = process.env.CANVAS_API_DOMAIN 6 | 7 | /** 8 | * Retrieves all quiz submissions in a course 9 | * @param {Number} courseId the course id. 10 | * @param {Number} quizId the quiz id. 11 | * @param {Array} options an array of options to include. 12 | * @return {Promise} A promise that resolves to a list of Quiz submission objects: https://canvas.instructure.com/doc/api/submissions.html 13 | */ 14 | 15 | export default function getQuizSubmissions (courseId, quizId, ...options) { 16 | return fetchAll(canvasDomain + `/courses/${courseId}/quizzes/${quizId}/submissions?` + buildOptions(options)) 17 | } 18 | -------------------------------------------------------------------------------- /src/showCustomGradebookColumn.js: -------------------------------------------------------------------------------- 1 | import putRequest from './internal/put.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Show custom gradebook column that was hidden 7 | * @param {Number} courseId the course ID of the target course. 8 | * @param {Number} columnId the position of the column, starting from left to right, indexed at 1. 9 | * @return {Promise} A promise that resolves to a CustomColumn object: https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#CustomColumn 10 | */ 11 | 12 | export default function showCustomGradebookColumn (courseId, columnId) { 13 | return putRequest(canvasDomain + `/courses/${courseId}/custom_gradebook_columns/${columnId}`, { 14 | 'column[hidden]': false 15 | }) 16 | } 17 | -------------------------------------------------------------------------------- /src/createUserCourseEnrollment.js: -------------------------------------------------------------------------------- 1 | import postRequest from './internal/post.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Create a new user enrollment for a course. 7 | * @param {Number} courseId the course ID the user is to be enrolled in. 8 | * @param {Number} body the object that contains the request parameters as indicated here: 9 | * https://canvas.instructure.com/doc/api/enrollments.html#method.enrollments_api.create 10 | * @return {Promise} An Enrollment object: https://canvas.instructure.com/doc/api/enrollments.html#Enrollment 11 | */ 12 | 13 | export default function createUserCourseEnrollment (courseId, body) { 14 | return postRequest(canvasDomain + `/courses/${courseId}/enrollments`, body) 15 | } 16 | -------------------------------------------------------------------------------- /src/createUserSectionEnrollment.js: -------------------------------------------------------------------------------- 1 | import postRequest from './internal/post.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Create a new user enrollment for section. 7 | * @param {Number} sectionId the section ID the user is to be enrolled in. 8 | * @param {Number} body the object that contains the request parameters as indicated here: 9 | * https://canvas.instructure.com/doc/api/enrollments.html#method.enrollments_api.create 10 | * @return {Promise} An Enrollment object: https://canvas.instructure.com/doc/api/enrollments.html#Enrollment 11 | */ 12 | 13 | export default function createUserSectionEnrollment (sectionId, body) { 14 | return postRequest(canvasDomain + `/sections/${sectionId}/enrollments`, body) 15 | } 16 | -------------------------------------------------------------------------------- /src/getModuleItems.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves all module items in a module 8 | * @param {Number} courseId the course id. 9 | * @param {Number} moduleId the module id. 10 | * @param {Array} options an array of options to include. 11 | * @return {Promise} A promise that resolves to a list of ModuleItem objects: https://canvas.instructure.com/doc/api/modules.html 12 | */ 13 | 14 | export default function getModuleItems (courseId, moduleId, ...options) { 15 | return fetchAll( 16 | canvasDomain + 17 | `/courses/${courseId}/modules/${moduleId}/items?` + 18 | buildOptions(options) 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /src/batchCopyCourseContent.js: -------------------------------------------------------------------------------- 1 | import copyCourseContent from './copyCourseContent.js' 2 | 3 | /** 4 | * Batch copy course content, takes in an array of objects that hold the sourceID and targetIds. 5 | * @param {Array} listOfSourceAndTargetCourseIds an array of objects { sourceCourseId, targetCourseId }. 6 | * @return {Promise} A promise that resolves to a list of progress IDs that can be used to look up progress 7 | * of copy 8 | */ 9 | 10 | const batchCopyCourseContent = async listOfSourceAndTargetCourseIds => { 11 | const listOfProgress = listOfSourceAndTargetCourseIds 12 | .map(({ sourceCourseId, targetCourseId }) => 13 | copyCourseContent(sourceCourseId, targetCourseId)) 14 | return listOfProgress 15 | } 16 | 17 | export default batchCopyCourseContent 18 | -------------------------------------------------------------------------------- /src/deleteSubmissionComment.js: -------------------------------------------------------------------------------- 1 | import deleteRequest from './internal/del.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Delete Submission comment 7 | * @param {Number} courseId the course ID of the target course. 8 | * @param {Number} assignmentId the assignment id. 9 | * @param {Number} userId the user id. 10 | * @param {Number} commentId the comment id. 11 | * @return {Promise} A SubmissionComment object: https://canvas.instructure.com/doc/api/submissions.html#SubmissionComment 12 | */ 13 | 14 | export default function deleteSubmissionComment (courseId, assignmentId, userId, commentId) { 15 | return deleteRequest(canvasDomain + `/courses/${courseId}/assignments/${assignmentId}/submissions/${userId}/comments/${commentId}`) 16 | } 17 | -------------------------------------------------------------------------------- /src/copyCourseContent.js: -------------------------------------------------------------------------------- 1 | import courseCopy from './courseCopy.js' 2 | import getProgress from './getProgress.js' 3 | 4 | /** 5 | * Initiates course copy. 6 | * @param {Number} sourceCourseId the course ID of the source course. 7 | * @param {Number} targetCourseId the course ID of the target course. 8 | * @return {Promise} A promise that resolves to a progress ID that can be used to look up progress 9 | * of copy 10 | */ 11 | 12 | const copyCourseContent = async (sourceCourseId, targetCourseId) => { 13 | const contentMigration = await courseCopy(sourceCourseId, targetCourseId) 14 | const progress = getProgress(contentMigration.id) 15 | // maybe implement polling to see when the content migration is complete? 16 | return progress 17 | } 18 | 19 | export default copyCourseContent 20 | -------------------------------------------------------------------------------- /src/getAssignmentSubmissions.js: -------------------------------------------------------------------------------- 1 | import fetchAll from './internal/fetchAll.js' 2 | import buildOptions from './internal/util.js' 3 | 4 | const canvasDomain = process.env.CANVAS_API_DOMAIN 5 | 6 | /** 7 | * Retrieves all assignment submissions in a course 8 | * @param {Number} courseId the course id. 9 | * @param {Number} assignmentId the assignment id. 10 | * @param {Array} options an array of options to include. 11 | * @return {Promise} A promise that resolves to a list of Assignment submission objects: https://canvas.instructure.com/doc/api/submissions.html 12 | */ 13 | 14 | export default function getAssignmentSubmissions (courseId, assignmentId, ...options) { 15 | return fetchAll(canvasDomain + `/courses/${courseId}/assignments/${assignmentId}/submissions?` + buildOptions(options)) 16 | } 17 | -------------------------------------------------------------------------------- /src/getRubric.js: -------------------------------------------------------------------------------- 1 | import fetch from './internal/fetch.js' 2 | import buildOptions from './internal/util.js' 3 | import getOptions from './internal/getOptions.js' 4 | 5 | const canvasDomain = process.env.CANVAS_API_DOMAIN 6 | 7 | /** 8 | * Retrieves a single rubric 9 | * @param {Number} courseId the course id. 10 | * @param {Number} rubricId the rubric id. 11 | * @param {Array} options an array of options to include. 12 | * @return {Promise} A promise that resolves to a Rubric object: https://canvas.instructure.com/doc/api/rubrics.html 13 | */ 14 | 15 | export default function getRubric (courseId, rubricId, ...options) { 16 | return fetch(canvasDomain + `/courses/${courseId}/rubrics/${rubricId}?` + buildOptions([getOptions.rubric.graded_assessments, getOptions.rubric.data_assessment, options])) 17 | } 18 | -------------------------------------------------------------------------------- /src/deleteAllCustomGradebookColumns.js: -------------------------------------------------------------------------------- 1 | import getCustomGradeBookColumns from './getCustomGradeBookColumns.js' 2 | import deleteCustomGradebookColumn from './deleteCustomGradebookColumn.js' 3 | 4 | /** 5 | * Deletes all custom gradebook columns 6 | * @param {Number} courseId the course ID of the target course. 7 | * @return {Promise} A list of CustomColumn objects: https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#CustomColumn 8 | */ 9 | 10 | const deleteAllCustomGradebookColumns = async courseId => { 11 | const allCustomGradebookColumns = await getCustomGradeBookColumns(courseId) 12 | const deleteAll = Promise.all(allCustomGradebookColumns.map(({ id }) => deleteCustomGradebookColumn(courseId, id))) 13 | return deleteAll 14 | } 15 | 16 | export default deleteAllCustomGradebookColumns 17 | -------------------------------------------------------------------------------- /src/getAllCourseSyllabiInAccount.js: -------------------------------------------------------------------------------- 1 | import getAllCoursesInAccount from './getAllCoursesInAccount.js' 2 | import getSyllabusOfCourse from './getSyllabusOfCourse.js' 3 | 4 | /** 5 | * Returns the syllabi of all courses contained under an Account 6 | * If a course does not have a syllabus defined, the syllabus_body will have null. 7 | * @param {Number} accountId the account ID for Canvas 8 | * @return {Promise} A promise that resolves to an array of course objects, with syllabus 9 | */ 10 | 11 | const getAllCourseSyllabiInAccount = async (accountId) => { 12 | const courses = await getAllCoursesInAccount(accountId) 13 | const ids = courses.map(({ id }) => id) 14 | const syllabi = await Promise.all( 15 | ids.map(id => getSyllabusOfCourse(id)) 16 | ) 17 | return syllabi 18 | } 19 | 20 | export default getAllCourseSyllabiInAccount 21 | -------------------------------------------------------------------------------- /src/getSyllabusOfCourse.js: -------------------------------------------------------------------------------- 1 | import getOptions from './internal/getOptions.js' 2 | import fetch from './internal/fetch.js' 3 | import buildOptions from './internal/util.js' 4 | 5 | const canvasDomain = process.env.CANVAS_API_DOMAIN 6 | 7 | /** 8 | * Retrieves syllabus of course 9 | * @param {Number} courseId the course id. 10 | * @return {Promise} A promise that resolves to a custom object: { courseCode, courseID, syllabus } 11 | */ 12 | 13 | export default function getSyllabusOfCourse (courseId) { 14 | return fetch(canvasDomain + `/courses/${courseId}?` + buildOptions([getOptions.courses.include.syllabus_body, getOptions.courses.include.term])) 15 | .then(course => ({ 16 | courseCode: course.course_code, 17 | courseId, 18 | syllabus: course.syllabus_body, 19 | name: course.name, 20 | term: course.term 21 | })) 22 | } 23 | -------------------------------------------------------------------------------- /src/getQuizSubmissionEvents.js: -------------------------------------------------------------------------------- 1 | import buildOptions from './internal/util.js' 2 | 3 | import fetchAll from './internal/fetchAll.js' 4 | 5 | const canvasDomain = process.env.CANVAS_API_DOMAIN 6 | 7 | /** 8 | * Retrieves all quiz submission events in a course 9 | * @param {Number} courseId the course id. 10 | * @param {Number} quizId the quiz id. 11 | * @param {Number} submissionId the submission id. 12 | * @param {Array} options an array of options to include. 13 | * @return {Promise} A promise that resolves to a list of Quiz submission event objects: https://canvas.instructure.com/doc/api/submissions.html 14 | */ 15 | 16 | export default function getQuizSubmissionEvents (courseId, quizId, submissionId, ...options) { 17 | return fetchAll(canvasDomain + `/courses/${courseId}/quizzes/${quizId}/submissions/${submissionId}/events?` + buildOptions(options)) 18 | } 19 | -------------------------------------------------------------------------------- /src/putStudentNumberInGradeColumn.js: -------------------------------------------------------------------------------- 1 | import putRequest from './internal/put.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Put student number in grade column 7 | * @param {Number} courseId the course ID of the target course. 8 | * @param {Number} gradebookColumnId the position of the column, starting from left to right, indexed at 1. 9 | * @param {Number} studentId the student ID 10 | * @param {Object} body the object to put 11 | * @return {Promise} A promise that resolves to a CustomColumn object: https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#CustomColumn 12 | */ 13 | 14 | export default function putStudentNumberInGradeColumn (courseId, gradebookColumnId, studentId, body) { 15 | return putRequest(canvasDomain + `/courses/${courseId}/custom_gradebook_columns/${gradebookColumnId}/data/${studentId}`, body) 16 | } 17 | -------------------------------------------------------------------------------- /src/createCustomGradebookColumn.js: -------------------------------------------------------------------------------- 1 | import postRequest from './internal/post.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Creates custom gradebook column 7 | * @param {Number} courseId the course ID of the target course. 8 | * @param {String} columnTitle the title of the custom column. 9 | * @param {Number} columnPosition the position of the column, starting from left to right, indexed at 1. 10 | * @return {Promise} A promise that resolves to a CustomColumn object: https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#CustomColumn 11 | */ 12 | 13 | export default function createCustomGradebookColumn (courseId, columnTitle, columnPosition) { 14 | return postRequest(canvasDomain + `/courses/${courseId}/custom_gradebook_columns`, { 15 | 'column[title]': columnTitle, 16 | 'column[position]': columnPosition 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /src/getAllCoursesInAccount.js: -------------------------------------------------------------------------------- 1 | import getSubaccounts from './getSubaccounts.js' 2 | import getCourses from './getCourses.js' 3 | import getOptions from './internal/getOptions.js' 4 | import { flatten } from 'ramda' 5 | 6 | /** 7 | * Retrieves every course in an account. 8 | * @param {Number} accountId the account id. 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a list of Course objects: https://canvas.instructure.com/doc/api/courses.html#Course 11 | */ 12 | 13 | const getAllCoursesInAccount = async (accountId, ...options) => { 14 | const accounts = await getSubaccounts(accountId) 15 | const courses = await Promise.all( 16 | accounts.map(({ id }) => getCourses(id, getOptions.courses.include.term, ...options)) 17 | ) 18 | return flatten(courses) 19 | } 20 | 21 | export default getAllCoursesInAccount 22 | -------------------------------------------------------------------------------- /src/internal/fetchAll.js: -------------------------------------------------------------------------------- 1 | import nodeFetch from 'node-fetch' 2 | import linkparser from 'parse-link-header' 3 | import Bottleneck from 'bottleneck' 4 | import dotenv from 'dotenv' 5 | 6 | dotenv.config() 7 | 8 | const token = process.env.CANVAS_API_TOKEN 9 | 10 | const limiter = new Bottleneck({ 11 | maxConcurrent: 20, 12 | minTime: 100 13 | }) 14 | 15 | const requestObj = { 16 | method: 'GET', 17 | headers: { 18 | 'Authorization': 'Bearer ' + token 19 | } 20 | } 21 | 22 | const fetchAll = async (url, result = []) => { 23 | const response = await nodeFetch(url, requestObj) 24 | const data = await response.json() 25 | result = [...result, ...data] 26 | 27 | const links = linkparser(response.headers.get('link')) 28 | return links?.next ? fetchAll(links.next.url, result) : result 29 | } 30 | 31 | const fetchAllRateLimited = limiter.wrap(fetchAll) 32 | 33 | export default fetchAllRateLimited 34 | -------------------------------------------------------------------------------- /src/postAssignmentSubmissionComment.js: -------------------------------------------------------------------------------- 1 | import putRequest from './internal/put.js' 2 | 3 | const canvasDomain = process.env.CANVAS_API_DOMAIN 4 | 5 | /** 6 | * Put student number in grade column 7 | * @param {Number} courseId the course ID of the target course. 8 | * @param {Number} gradebookColumnId the position of the column, starting from left to right, indexed at 1. 9 | * @param {Number} studentId the student ID 10 | * @param {Object} body the object to put 11 | * @return {Promise} A promise that resolves to a CustomColumn object: https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#CustomColumn 12 | */ 13 | 14 | export default function postAssignmentSubmissionComment (courseId, assignmentId, studentId, text) { 15 | return putRequest(canvasDomain + `/courses/${courseId}/assignments/${assignmentId}/submissions/${studentId}`, { 16 | 'comment': { 17 | 'text_comment': text 18 | } 19 | }) 20 | } 21 | -------------------------------------------------------------------------------- /src/getAllCoursesInDept.js: -------------------------------------------------------------------------------- 1 | import getDeptIdsInAccount from './getDeptIdsInAccount.js' 2 | import getOptions from './internal/getOptions.js' 3 | import getCourses from './getCourses.js' 4 | 5 | /** 6 | * Retrieves every course in an account. 7 | * @param {Number} accountId the account id. 8 | * @param {String} deptName name of the dept (APBI, FNH, etc). 9 | * @param {Array} options an array of options to include. 10 | * @return {Promise} A promise that resolves to a list of Course objects: https://canvas.instructure.com/doc/api/courses.html#Course 11 | */ 12 | 13 | const getAllCoursesInDept = async (accountId, deptName, ...options) => { 14 | const deptIds = await getDeptIdsInAccount(accountId) 15 | const idOfDept = deptIds.find(dept => dept.name === deptName).id 16 | const coursesInDept = getCourses(idOfDept, getOptions.courses.include.term, ...options) 17 | return coursesInDept 18 | } 19 | 20 | export default getAllCoursesInDept 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-canvas-api", 3 | "version": "2.0.0", 4 | "description": "Canvas LMS API for Node", 5 | "files": [ 6 | "src" 7 | ], 8 | "main": "src/index.js", 9 | "author": "Justin Lee", 10 | "license": "MIT", 11 | "type": "module", 12 | "dependencies": { 13 | "bottleneck": "^2.19.4", 14 | "dotenv": "^4.0.0", 15 | "node-fetch": "^3.3.2", 16 | "parse-link-header": "^2.0.0", 17 | "ramda": "^0.27.2" 18 | }, 19 | "keywords": [ 20 | "canvas", 21 | "lms", 22 | "client", 23 | "api", 24 | "instructure" 25 | ], 26 | "repository": { 27 | "type": "git", 28 | "url": "git+https://github.com/ubc/node-canvas-api.git" 29 | }, 30 | "bugs": { 31 | "url": "https://github.com/ubc/node-canvas-api/issues" 32 | }, 33 | "homepage": "https://github.com/ubc/node-canvas-api#readme", 34 | "devDependencies": { 35 | "@babel/cli": "^7.25.9", 36 | "@babel/core": "^7.26.0", 37 | "@babel/preset-env": "^7.26.0" 38 | } 39 | } -------------------------------------------------------------------------------- /src/putStudentNumberInExistingCustomColumn.js: -------------------------------------------------------------------------------- 1 | import getOptions from './internal/getOptions.js' 2 | import getUsersInCourse from './getUsersInCourse.js' 3 | import putStudentNumberInGradeColumn from './putStudentNumberInGradeColumn.js' 4 | 5 | /** 6 | * Put student number in existing custom column by ID 7 | * @param {Number} courseId the course ID of the target course. 8 | * @param {Number} customGradeBookId the ID of the custom gradebook ID. 9 | * @return {Promise} A promise that resolves to a CustomColumn object: https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#CustomColumn 10 | */ 11 | 12 | const putStudentNumberInExistingCustomColumn = async (courseId, customGradeBookId) => { 13 | const studentObjs = await getUsersInCourse(courseId, getOptions.users.enrollmentType.student) 14 | const customGradebookResponse = Promise.all( 15 | studentObjs.map(({ id, sis_user_id }) => 16 | putStudentNumberInGradeColumn(courseId, customGradeBookId, id, { 'column_data[content]': sis_user_id })) 17 | ) 18 | return customGradebookResponse 19 | } 20 | 21 | export default putStudentNumberInExistingCustomColumn 22 | -------------------------------------------------------------------------------- /src/hideCustomGradebookColumnsByName.js: -------------------------------------------------------------------------------- 1 | import getCustomGradeBookColumns from './getCustomGradeBookColumns.js' 2 | import hideCustomGradebookColumn from './hideCustomGradebookColumn.js' 3 | 4 | /** 5 | * Hide Custom Gradebook Column by Name 6 | * @param {Number} courseId the course ID of the target course. 7 | * @param {Array} gradebookColumnNames the title of the custom column. 8 | * @return {Promise} A promise that resolves to a list of CustomColumn object: https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#CustomColumn 9 | */ 10 | 11 | const hideCustomGradebookColumnsByName = async (courseId, ...gradebookColumnNames) => { 12 | const customGradebookColumns = await getCustomGradeBookColumns(courseId) 13 | const matchingGradebookColumnID = customGradebookColumns 14 | .filter(({ title }) => (gradebookColumnNames.includes(title))) 15 | .map(gradebookColumn => gradebookColumn.id) 16 | const response = Promise.all( 17 | matchingGradebookColumnID.map(gradebookId => 18 | hideCustomGradebookColumn(courseId, gradebookId)) 19 | ) 20 | return response 21 | } 22 | 23 | export default hideCustomGradebookColumnsByName 24 | -------------------------------------------------------------------------------- /src/showCustomGradebookColumnsByName.js: -------------------------------------------------------------------------------- 1 | import getCustomGradeBookColumns from './getCustomGradeBookColumns.js' 2 | import showCustomGradebookColumn from './showCustomGradebookColumn.js' 3 | 4 | /** 5 | * Show Custom Gradebook Column by Name 6 | * @param {Number} courseId the course ID of the target course. 7 | * @param {Array} gradebookColumnNames the title of the custom column. 8 | * @return {Promise} A promise that resolves to a list of CustomColumn object: https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#CustomColumn 9 | */ 10 | 11 | const showCustomGradebookColumnsByName = async (courseId, ...gradebookColumnNames) => { 12 | const customGradebookColumns = await getCustomGradeBookColumns(courseId) 13 | const matchingGradebookColumnID = customGradebookColumns 14 | .filter(({ title }) => (gradebookColumnNames.includes(title))) 15 | .map(gradebookColumn => gradebookColumn.id) 16 | const response = Promise.all( 17 | matchingGradebookColumnID.map(gradebookId => 18 | showCustomGradebookColumn(courseId, gradebookId)) 19 | ) 20 | return response 21 | } 22 | 23 | export default showCustomGradebookColumnsByName 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 UBC Faculty of Land and Food Systems 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # https://github.com/github/gitignore/blob/master/Node.gitignore # 2 | ################################################################## 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (http://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # Typescript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # Custom 64 | .idea 65 | DS_Store 66 | .vscode 67 | 68 | # google sheets sample 69 | client_secret.json 70 | credentials.json 71 | quickstart.json 72 | test.js 73 | /index.js -------------------------------------------------------------------------------- /src/putStudentNumbersInGradebook.js: -------------------------------------------------------------------------------- 1 | import getOptions from './internal/getOptions.js' 2 | import getUsersInCourse from './getUsersInCourse.js' 3 | import createCustomGradebookColumn from './createCustomGradebookColumn.js' 4 | import putStudentNumberInGradeColumn from './putStudentNumberInGradeColumn.js' 5 | 6 | /** 7 | * Create gradebook with default title 'Student Number' and default column position 1 and 8 | * add student numbers to this column 9 | * @param {Number} courseId the course ID of the target course. 10 | * @param {String} columnTitle the title of the custom column. 11 | * @param {Number} columnPosition the position of the column, starting from left to right, indexed at 1. 12 | * @return {Promise} A promise that resolves to a list of CustomColumn object: 13 | * https://canvas.instructure.com/doc/api/custom_gradebook_columns.html#CustomColumn 14 | */ 15 | 16 | const putStudentNumbersInGradebook = async (courseId, columnTitle = 'Student Number', columnPosition = 1) => { 17 | const customGradeBook = await createCustomGradebookColumn(courseId, columnTitle, columnPosition) 18 | const customGradeBookId = customGradeBook.id 19 | const studentObjs = await getUsersInCourse(courseId, getOptions.users.enrollmentType.student) 20 | const customGradebookResponse = Promise.all( 21 | studentObjs.map(({ id, sis_user_id }) => 22 | putStudentNumberInGradeColumn(courseId, customGradeBookId, id, { 'column_data[content]': sis_user_id })) 23 | ) 24 | return customGradebookResponse 25 | } 26 | 27 | export default putStudentNumbersInGradebook 28 | -------------------------------------------------------------------------------- /src/downloadFile.js: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch' 2 | import getFile from './getFile.js' 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | const token = process.env.CANVAS_API_TOKEN 7 | 8 | /** 9 | * Downloads specified fileID from Canvas to specified path 10 | * @param {Number} fileId the fileId of the file 11 | * @param {String} downloadPath the path that the file should be downloaded to 12 | * @return {Promise} A Promise that resolves to a log that indicates what the filename of the downloaded file is. On error, logs the error 13 | */ 14 | 15 | const downloadFile = async (fileId, downloadPath) => { 16 | try { 17 | const { url, filename } = await getFile(fileId, downloadPath) 18 | const modifiedName = filename 19 | .replace(/%28/g, '(') 20 | .replace(/%29/g, ')') 21 | .replace(/%E2%80%93/g, '-') 22 | 23 | const fileStream = fs.createWriteStream(path.join(downloadPath, modifiedName)) 24 | 25 | const response = await fetch(url, { 26 | method: 'GET', 27 | headers: { 28 | 'Authorization': `Bearer ${token}` 29 | } 30 | }) 31 | 32 | if (!response.ok) { 33 | throw new Error(`Failed to download file: ${response.statusText}`) 34 | } 35 | 36 | // Pipe the response body to the file stream 37 | response.body.pipe(fileStream) 38 | 39 | return new Promise((resolve, reject) => { 40 | fileStream.on('finish', () => resolve(modifiedName)) 41 | fileStream.on('error', err => reject(err)) 42 | }) 43 | } catch (error) { 44 | console.error(`Error downloading file: ${error.message}`) 45 | throw error // Rethrow the error after logging 46 | } 47 | } 48 | 49 | export default downloadFile 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![npm version](https://badge.fury.io/js/node-canvas-api.svg)](https://badge.fury.io/js/node-canvas-api) 2 | [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) 3 | [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest) 4 | 5 | # Canvas LMS API for Node.js 6 | Canvas API functions bundled as a NPM package for Node.js. Note: this package no longer supports CJS as of [version 2.0.0](https://www.npmjs.com/package/node-canvas-api/v/2.0.0). If you need CJS support, please use [version 1.8.0](https://www.npmjs.com/package/node-canvas-api/v/1.8.0). 7 | 8 | ## Getting Started 9 | These instructions will get you a copy of the project up and running on your local machine for use with your own API tokens and Canvas domains. 10 | 11 | ### Prerequisites 12 | 13 | 1. **Install [Node LTS (20 or greater)](https://nodejs.org)**. 14 | 15 | ### Installation 16 | 17 | To use with NodeJS: 18 | ```bash 19 | $ npm install node-canvas-api 20 | ``` 21 | 22 | Rename the `sample.env` file to `.env` and add your institution's domain and API access token. 23 | 24 | Attached to the `canvasAPI` are a [bunch of functions](https://github.com/ubc/node-canvas-api/tree/master/src). 25 | Run the attached functions! 26 | 27 | ### Example Usage 28 | 29 | #### Get information about self: 30 | ```js 31 | import { getSelf } from 'node-canvas-api' 32 | 33 | getSelf().then(x => console.log(x)) 34 | ``` 35 | 36 | #### Get students in a course: 37 | ```js 38 | import { getUsersInCourse, getOptions } from 'node-canvas-api' 39 | 40 | getUsersInCourse(12345, getOptions.users.enrollmentType.student) // first argument is Canvas course ID 41 | .then(students => console.log(students)) 42 | ``` 43 | 44 | ## Contribute 45 | Contributions are welcome and greatly appreciated! 46 | 47 | ### How to contribute 48 | 1. Create an [issue](https://github.com/ubc/node-canvas-api/issues) describing what contribution you are planning to make. 49 | 1. Fork the repo. 50 | 1. Add your contributions. 51 | 1. Once you're happy with your contribution, open an [pull request](https://github.com/ubc/node-canvas-api/pulls) and I'll take a look. 52 | 53 | ## Usage 54 | * [Canvas Rubrics](https://github.com/ubc/canvas-rubric) 55 | * [Canvas Discussions](https://github.com/ubc/canvas-discussion) 56 | * [Canvas Syllabus](https://github.com/UBC-LFS/lfs-canvas-syllabus) 57 | 58 | ## License 59 | 60 | This project is licensed under the MIT License. 61 | -------------------------------------------------------------------------------- /src/internal/getOptions.js: -------------------------------------------------------------------------------- 1 | const getOptions = { 2 | users: { 3 | search: term => `search_term=${encodeURIComponent(term)}`, 4 | sort: { 5 | username: 'sort=username', 6 | email: 'sort=email', 7 | sis_id: 'sort=sis_id', 8 | last_login: 'sort=last_login' 9 | }, 10 | order: { 11 | asc: 'order=asc', 12 | desc: 'order=desc' 13 | }, 14 | enrollmentType: { 15 | teacher: 'enrollment_type[]=teacher', 16 | student: 'enrollment_type[]=student', 17 | student_view: 'enrollment_type[]=student_view', 18 | ta: 'enrollment_type[]=ta', 19 | observer: 'enrollment_type[]=observer', 20 | designer: 'enrollment_type[]=designer' 21 | }, 22 | include: { 23 | email: 'include[]=email', 24 | enrollments: 'include[]=enrollments', 25 | locked: 'include[]=locked', 26 | avatar_url: 'include[]=avatar_url', 27 | test_student: 'include[]=test_student', 28 | bio: 'include[]=bio', 29 | custom_links: 'include[]=custom_links', 30 | current_grading_period_scores: 'include[]=current_grading_period_scores', 31 | term: 'include[]=term', 32 | students: 'include[]=students', 33 | user: 'include[]=user' 34 | }, 35 | userIds: id => `user_ids[]=${encodeURIComponent(id)}`, 36 | enrollmentState: { 37 | active: 'enrollment_state=active', 38 | invited: 'enrollment_state=invited', 39 | rejected: 'enrollment_state=rejected', 40 | completed: 'enrollment_state=completed', 41 | inactive: 'enrollment_state=inactive' 42 | } 43 | }, 44 | courses: { 45 | include: { 46 | needs_grading_count: 'include[]=needs_grading_count', 47 | syllabus_body: 'include[]=syllabus_body', 48 | public_description: 'include[]=public_description', 49 | total_scores: 'include[]=total_scores', 50 | current_grading_period_scores: 'include[]=current_grading_period_scores', 51 | term: 'include[]=term', 52 | course_progress: 'include[]=course_progress', 53 | sections: 'include[]=sections', 54 | storage_quota_used_mb: 'include[]=storage_quota_used_mb', 55 | total_students: 'include[]=total_students', 56 | passback_status: 'include[]=passback_status', 57 | favorites: 'include[]=favorites', 58 | teachers: 'include[]=teachers', 59 | observed_users: 'include[]=observed_users' 60 | }, 61 | state: { 62 | unpublished: 'state[]=unpublished', 63 | available: 'state[]=available', 64 | completed: 'state[]=completed', 65 | deleted: 'state[]=deleted' 66 | }, 67 | enrollmentState: { 68 | active: 'enrollment_state=active', 69 | invited_or_pending: 'enrollment_state=invited_or_pending', 70 | completed: 'enrollment_state=completed' 71 | } 72 | }, 73 | account: { 74 | with_enrollments: 'with_enrollments=true', 75 | enrollment_type: role => `enrollment_type[]=${encodeURIComponent(role)}`, 76 | published: 'published=true', 77 | completed: 'completed=true', 78 | blueprint: 'blueprint=true' 79 | }, 80 | submissions: { 81 | rubric_assessment: 'include[]=rubric_assessment', 82 | submission_comments: 'include[]=submission_comments', 83 | submission: 'include[]=submission' 84 | }, 85 | quiz: { 86 | quiz: 'include[]=quiz' 87 | }, 88 | rubric: { 89 | assessments: 'include=assessments', 90 | graded_assessments: 'include=graded_assessments', 91 | peer_assessments: 'include=peer_assessments', 92 | data_assessment: 'style=full' 93 | }, 94 | module: { 95 | include: { 96 | items: 'include[]=items', 97 | content_details: 'include[]=content_details' 98 | } 99 | }, 100 | discussion: { 101 | include: { 102 | all_dates: 'include[]=all_dates', 103 | sections: 'include[]=sections', 104 | sections_user_count: 'include[]=sections_user_count', 105 | overrides: 'include[]=overrides' 106 | }, 107 | order_by: { 108 | position: 'orderby=position', 109 | recent_activity: 'orderby=recent_activity', 110 | title: 'orderby=title' 111 | }, 112 | scope: { 113 | locked: 'scope=locked', 114 | unlocked: 'scope=unlocked', 115 | pinned: 'scope=pinned', 116 | unpinned: 'scope=unpinned' 117 | }, 118 | only_announcements: 'only_announcements=true', 119 | filter_by: { 120 | all: 'filter_by=all', 121 | unread: 'filter_by=unread' 122 | } 123 | } 124 | } 125 | 126 | export default getOptions 127 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | export { default as batchCopyCourseContent } from './batchCopyCourseContent.js' 2 | export { default as copyCourseContent } from './copyCourseContent.js' 3 | export { default as createCourse } from './createCourse.js' 4 | export { default as createCustomGradebookColumn } from './createCustomGradebookColumn.js' 5 | export { default as createUser } from './createUser.js' 6 | export { default as createUserCourseEnrollment } from './createUserCourseEnrollment.js' 7 | export { default as createUserSectionEnrollment } from './createUserSectionEnrollment.js' 8 | export { default as deleteAllCustomGradebookColumns } from './deleteAllCustomGradebookColumns.js' 9 | export { default as downloadFile } from './downloadFile.js' 10 | export { default as deleteCustomGradebookColumn } from './deleteCustomGradebookColumn.js' 11 | export { default as getAccountIds } from './getAccountIds.js' 12 | export { default as getAccounts } from './getAccounts.js' 13 | export { default as getAllCoursesInAccount } from './getAllCoursesInAccount.js' 14 | export { default as getAllCoursesInDept } from './getAllCoursesInDept.js' 15 | export { default as getAllCourseSyllabiInAccount } from './getAllCourseSyllabiInAccount.js' 16 | export { default as getAnalytics } from './getAnalytics.js' 17 | export { default as getAssignments } from './getAssignments.js' 18 | export { default as getCourses } from './getCourses.js' 19 | export { default as getCoursesByUser } from './getCoursesByUser.js' 20 | export { default as getCustomGradeBookColumns } from './getCustomGradeBookColumns.js' 21 | export { default as getDeptIdsInAccount } from './getDeptIdsInAccount.js' 22 | export { default as getProgress } from './getProgress.js' 23 | export { default as getSubaccounts } from './getSubaccounts.js' 24 | export { default as getSyllabusOfCourse } from './getSyllabusOfCourse.js' 25 | export { default as getUserPageViews } from './getUserPageViews.js' 26 | export { default as getUsersInAccount } from './getUsersInAccount.js' 27 | export { default as getUsersInCourse } from './getUsersInCourse.js' 28 | export { default as hideCustomGradebookColumn } from './hideCustomGradebookColumn.js' 29 | export { default as hideCustomGradebookColumnsByName } from './hideCustomGradebookColumnsByName.js' 30 | export { default as putStudentNumberInExistingCustomColumn } from './putStudentNumberInExistingCustomColumn.js' 31 | export { default as putStudentNumberInGradeColumn } from './putStudentNumberInGradeColumn.js' 32 | export { default as putStudentNumbersInGradebook } from './putStudentNumbersInGradebook.js' 33 | export { default as showCustomGradebookColumn } from './showCustomGradebookColumn.js' 34 | export { default as showCustomGradebookColumnsByName } from './showCustomGradebookColumnsByName.js' 35 | export { default as checkProgressStatus } from './checkProgressStatus.js' 36 | export { default as getOptions } from './internal/getOptions.js' 37 | export { default as getUser } from './getUser.js' 38 | export { default as getRubricsInCourse } from './getRubricsInCourse.js' 39 | export { default as getRubric } from './getRubric.js' 40 | export { default as getAssignmentSubmissions } from './getAssignmentSubmissions.js' 41 | export { default as getEnrollmentsInCourse } from './getEnrollmentsInCourse.js' 42 | export { default as getSections } from './getSections.js' 43 | export { default as getModules } from './getModules.js' 44 | export { default as getModuleItems } from './getModuleItems.js' 45 | export { default as getDiscussionTopics } from './getDiscussionTopics.js' 46 | export { default as getDiscussionTopic } from './getDiscussionTopic.js' 47 | export { default as getFullDiscussion } from './getFullDiscussion.js' 48 | export { default as getSelf } from './getSelf.js' 49 | export { default as getOutcome } from './getOutcome.js' 50 | export { default as getQuizSubmissions } from './getQuizSubmissions.js' 51 | export { default as getQuizSubmissionEvents } from './getQuizSubmissionEvents.js' 52 | export { default as getQuizQuestions } from './getQuizQuestions.js' 53 | export { default as getCourseAnalytics } from './getCourseAnalytics.js' 54 | export { default as getPlannerItemsByUser } from './getPlannerItemsByUser.js' 55 | export { default as getGroupsInCourse } from './getGroupsInCourse.js' 56 | export { default as getGroupDiscussionTopics } from './getGroupDiscussionTopics.js' 57 | export { default as getFullGroupDiscussion } from './getFullGroupDiscussion.js' 58 | export { default as getGroupDiscussionTopic } from './getGroupDiscussionTopic.js' 59 | export { default as getQuizSubmission } from './getQuizSubmission.js' 60 | export { default as postAssignmentSubmissionComment } from './postAssignmentSubmissionComment.js' 61 | export { default as deleteSubmissionComment } from './deleteSubmissionComment.js' 62 | export { default as getCourse } from './getCourse.js' 63 | export { default as getCourseSections } from './getCourseSections.js' 64 | export { default as getEnrollmentsInSection } from './getEnrollmentsInSection.js' 65 | export { default as createGroup } from './createGroup.js' 66 | export { default as createGroupCategories } from './createGroupCategories.js' 67 | export { default as createGroupMembership } from './createGroupMembership.js' 68 | export { default as getHistory } from './getHistory.js' 69 | --------------------------------------------------------------------------------