### Install CanvasAPI with Pip Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/getting-started.md Install the CanvasAPI library using pip. This is the first step to using the library. ```bash pip install canvasapi ``` -------------------------------- ### Get All Users in a Course Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Retrieves a list of all users enrolled in a specific course. This is a foundational step for managing course participants. ```python users = course.get_users() for user in users: print(user) ``` -------------------------------- ### Retrieve User and Their Courses Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/getting-started.md Fetch a user by their ID and retrieve a list of courses they are enrolled in. Also shows how to get a user by SIS ID. ```python # Grab user 123 >>> user = canvas.get_user(123) # Access the user's name >>> user.name 'Test User' # Retrieve a list of courses the user is enrolled in >>> courses = user.get_courses() # Grab a different user by their SIS ID >>> login_id_user = canvas.get_user('some_user', 'sis_login_id') ``` -------------------------------- ### Update Course Start and End Dates Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Changes the start and end dates for a course. It supports both ISO8601 formatted date strings and Python datetime objects. ```python course.update( course={ 'start_at': '2018-01-01T00:01Z', 'end_at': '2018-12-31T11:59Z' } ) ``` ```python from datetime import datetime start_date = datetime(2018, 1, 1, 0, 1) end_date = datetime(2018, 12, 31, 11, 59) course.update( course={ 'start_at': start_date, 'end_at': end_date } ) ``` -------------------------------- ### Get Users by Enrollment Type and State Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Retrieves users from a course based on both their enrollment type and their enrollment state (e.g., active or invited). This provides granular control over user selection. ```python users = course.get_users( enrollment_type=['teacher', 'student'] enrollment_state=['active', 'invited'] ) for user in users: print(user) ``` -------------------------------- ### View CanvasAPI Request and Response Logs Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/debugging.md After configuring logging, this example shows the output generated by the CanvasAPI library when making a request, including the request details, headers, and the response data. This helps in understanding the library's interaction with the Canvas API. ```python # A previously configured `Canvas` client >>> canvas.get_current_user() 2019-07-08 14:22:24,517 - canvasapi.requester - INFO - Request: GET https://base/api/v1/users/self 2019-07-08 14:22:24,517 - canvasapi.requester - DEBUG - Headers: {'Authorization': '****4BSt'} 2019-07-08 14:22:24,748 - canvasapi.requester - INFO - Response: GET https://base/api/v1/users/self 200 2019-07-08 14:22:24,749 - canvasapi.requester - DEBUG - Headers: {'Cache-Control': 'max-age=0, private, must-revalidate', 'Connection': 'keep-alive', 'Content-Encoding': 'gzip', 'Content-Length': '329', 'Content-Type': 'application/json; charset=utf-8', 2019-07-08 14:22:24,749 - canvasapi.requester - DEBUG - Data: {'avatar_url': 'https://base/images/thumbnails/43244/Umo5dyAg0OS3tpDtDN', 'created_at': '2014-08-22T08:02:00-04:00', 'effective_locale': 'en', 'email': '', 'id': XXXX181, 'integration_id': None, 'locale': None, 'login_id': 'XXXXXXXX181', 'name': 'Some User', 'permissions': {'can_update_avatar': True, 'can_update_name': False}, 'root_account': 'xxxxxx.edu', 'short_name': 'Some User', 'sis_user_id': 'XXXXXXXX181', 'sortable_name': 'User S'} ``` -------------------------------- ### GET /api/v1/folders/:id Source: https://github.com/ucfopen/canvasapi/blob/develop/tests/fixtures/files.html Returns the details for a specified folder. ```APIDOC ## GET /api/v1/folders/:id ### Description Returns the details for a folder ### Method GET ### Endpoint /api/v1/folders/:id ``` -------------------------------- ### Get All Assignments in a Course Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Fetches a list of all assignments within a course. This is useful for iterating through assignments to display or process them. ```python assignments = course.get_assignments() for assignment in assignments: print(assignment) ``` -------------------------------- ### GET /api/v1/courses/:course_id/folders/:id Source: https://github.com/ucfopen/canvasapi/blob/develop/tests/fixtures/files.html Retrieves details for a specific folder within a course. ```APIDOC ## GET /api/v1/courses/:course_id/folders/:id ### Description Retrieves details for a specific folder within a course. ### Method GET ### Endpoint /api/v1/courses/:course_id/folders/:id ``` -------------------------------- ### Get User's Active Courses with Keyword Arguments Source: https://github.com/ucfopen/canvasapi/blob/develop/README.md Retrieve a list of courses a user is actively enrolled in by passing keyword arguments to the get_courses method. Ensure the user object is properly initialized. ```python # Get all of the active courses a user is currently enrolled in >>> courses = user.get_courses(enrollment_state='active') ``` -------------------------------- ### PaginatedList Example Source: https://github.com/ucfopen/canvasapi/blob/develop/README.md Demonstrates accessing elements from a PaginatedList object, which is returned for API calls that retrieve multiple objects. Note that PaginatedList lazily loads elements and does not support negative indexing. ```python # Retrieve a list of courses the user is enrolled in >>> courses = user.get_courses() >>> print(courses) # Access the first element in our list. # # You'll notice the first call takes a moment, but the next N-1 ``` -------------------------------- ### GET /api/v1/users/:user_id/folders/:id Source: https://github.com/ucfopen/canvasapi/blob/develop/tests/fixtures/files.html Retrieves details for a specific folder associated with a user. ```APIDOC ## GET /api/v1/users/:user_id/folders/:id ### Description Retrieves details for a specific folder associated with a user. ### Method GET ### Endpoint /api/v1/users/:user_id/folders/:id ``` -------------------------------- ### Update Course Name Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Modifies the name of an existing course. This example shows how to update the course name and prints the name before and after the update. ```python print(course.name) # prints 'Old Name' course.update(course={'name': 'New Name'}) print(course.name) # prints 'New Name' ``` -------------------------------- ### Get Specific Enrollment Types of Users in a Course Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Filters users within a course based on their enrollment type. This allows you to retrieve only students, or specific roles like TAs and designers. ```python users = course.get_users(enrollment_type=['student']) for user in users: print(user) ``` ```python type_list = ['teacher', 'ta', 'designer'] users = course.get_users(enrollment_type=type_list) for user in users: print(user) ``` -------------------------------- ### Update an Assignment’s Name Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Modifies the name of an existing assignment. This example fetches an assignment first, then updates its name. ```python updated_assignment = assignment.edit(assignment={'name': 'New Name'}) print(updated_assignment) ``` -------------------------------- ### GET /api/v1/users/:user_id/communication_channels/:communication_channel_id/notification_preferences Source: https://github.com/ucfopen/canvasapi/blob/develop/tests/fixtures/notification_preferences.html Fetches all notification preferences for a specific communication channel, identified by its ID. ```APIDOC ## GET /api/v1/users/:user_id/communication_channels/:communication_channel_id/notification_preferences ### Description Fetches all notification preferences for the given communication channel, identified by its ID. ### Method GET ### Endpoint /api/v1/users/:user_id/communication_channels/:communication_channel_id/notification_preferences ### Parameters #### Path Parameters - **user_id** (integer) - Required - The ID of the user. - **communication_channel_id** (integer) - Required - The ID of the communication channel. ### Response #### Success Response (200) - **notification_preferences** (array) - A list of notification preference objects. ``` -------------------------------- ### Get Ungraded Assignments Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Retrieves only the assignments that have not yet been graded. This is helpful for instructors focusing on pending grading tasks. ```python assignments = course.get_assignments(bucket='ungraded') for assignment in assignments: print(assignment) ``` -------------------------------- ### GET /api/v1/groups/:group_id/folders/:id Source: https://github.com/ucfopen/canvasapi/blob/develop/tests/fixtures/files.html Retrieves details for a specific folder within a group. ```APIDOC ## GET /api/v1/groups/:group_id/folders/:id ### Description Retrieves details for a specific folder within a group. ### Method GET ### Endpoint /api/v1/groups/:group_id/folders/:id ``` -------------------------------- ### GET /api/v1/users/:user_id/communication_channels/:type/:address/notification_preferences Source: https://github.com/ucfopen/canvasapi/blob/develop/tests/fixtures/notification_preferences.html Fetches all notification preferences for a given communication channel, identified by its type and address. ```APIDOC ## GET /api/v1/users/:user_id/communication_channels/:type/:address/notification_preferences ### Description Fetches all notification preferences for the given communication channel, identified by its type and address. ### Method GET ### Endpoint /api/v1/users/:user_id/communication_channels/:type/:address/notification_preferences ### Parameters #### Path Parameters - **user_id** (integer) - Required - The ID of the user. - **type** (string) - Required - The type of the communication channel (e.g., 'email', 'sms'). - **address** (string) - Required - The address of the communication channel (e.g., an email address or phone number). ### Response #### Success Response (200) - **notification_preferences** (array) - A list of notification preference objects. ``` -------------------------------- ### Get a User’s Page Views Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Retrieves a list of page view events for a specific user. This can be used for analytics or tracking user activity within Canvas. ```python page_views = user.get_page_views() ``` -------------------------------- ### Get a Single Assignment Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Retrieves a specific assignment from a course using its ID. This is useful for viewing or modifying individual assignments. ```python # Grab assignment with ID of 1234 assignment = course.get_assignment(1234) print(assignment) ``` -------------------------------- ### Get a User by SIS ID Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Fetches a user object from Canvas using their Student Information System (SIS) login ID. This is a common way to look up users if you are integrating with an external system. ```python # Grab a user with the SIS ID of 'some_id' user = canvas.get_user('some_id', 'sis_login_id') ``` -------------------------------- ### Get a Course by Canvas ID Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Retrieves a specific course object using its unique Canvas ID. This is essential for performing any operations on a particular course. ```python # Grab course with ID of 123456 course = canvas.get_course(123456) ``` -------------------------------- ### Edit an Existing User Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Modifies the details of an existing user in Canvas. This example shows how to change a user's display name. Ensure the user object is fetched first. ```python # Grab the user user = canvas.get_user(1) user.edit( user={'name': 'New Name'} ) ``` -------------------------------- ### Get a User by Canvas ID Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Retrieves a user object using their unique Canvas internal ID. This is the most direct way to access a user if their Canvas ID is known. ```python # Grab user with ID of 1 user = canvas.get_user(1) ``` -------------------------------- ### Retrieve and Update a Course Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/getting-started.md Fetch a specific course by its ID and demonstrate how to access its properties and update them. ```python # Grab course 123456 >>> course = canvas.get_course(123456) # Access the course's name >>> course.name 'Test Course' # Update the course's name >>> course.update(course={'name': 'New Course Name'}) ``` -------------------------------- ### Passing Basic Parameters Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/keyword-args.md Pass simple string or integer parameters directly as keyword arguments. This is the most common way to pass parameters. ```python course.get_users(search_term='John Doe') ``` ```python course.get_users( search_term='John Doe', enrollment_role='StudentEnrollment' ) ``` -------------------------------- ### Create a Basic Assignment Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Creates a new assignment in a course with a specified name. This is the simplest form of assignment creation. ```python new_assignment = course.create_assignment({ 'name': 'Assignment 1' }) print(new_assignment) ``` -------------------------------- ### Create a Complex Assignment Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Creates a detailed assignment with specific settings including allowed file extensions, due dates, points, and a description. It also configures notifications and publishing status. ```python from datetime import datetime new_assignment = course.create_assignment({ 'name': 'Assignment 3', 'submission_types': ['online_upload'], 'allowed_extensions': ['docx', 'doc', 'pdf'], 'notify_of_update': True, 'points_possible': 100, 'due_at': datetime(2018, 12, 31, 11, 59), 'description': 'Please upload your homework as a Word document or PDF.', 'published': True }) ``` -------------------------------- ### Print First Course Object Source: https://github.com/ucfopen/canvasapi/blob/develop/README.md Access and print the first course object from a list of courses obtained from the CanvasAPI. ```python >>> print(courses[0]) TST101 Test Course (1234567) ``` -------------------------------- ### Instantiate Canvas Object Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/getting-started.md Initialize a new Canvas object with your API URL and key. This object is used for all subsequent API calls. ```python # Import the Canvas class from canvasapi import Canvas # Canvas API URL API_URL = "https://example.com" # Canvas API key API_KEY = "p@$$w0rd" # Initialize a new Canvas object canvas = Canvas(API_URL, API_KEY) ``` -------------------------------- ### Working with Paginated Lists Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/getting-started.md Demonstrates how to interact with PaginatedList objects, including accessing elements by index, iterating, and slicing. Note that negative indexing is not supported. ```python # Retrieve a list of courses the user is enrolled in >>> courses = user.get_courses() >>> print(courses) # Access the first element in our list. # # You'll notice the first call takes a moment, but the next N-1 # elements (where N = the per_page argument supplied; the default is 10) # will be instantly accessible. >>> print(courses[0]) TST101 Test Course (1234567) # Iterate over our course list >>> for course in courses: print(course) TST101 Test Course 1 (1234567) TST102 Test Course 2 (1234568) TST103 Test Course 3 (1234569) # Take a slice of our course list >>> courses[:2] [TST101 Test Course 1 (1234567), TST102 Test Course 2 (1234568)] ``` -------------------------------- ### Create a New User in an Account Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md This snippet demonstrates how to create a new user within a specific Canvas account. It requires the account ID and user details, including a pseudonym with a password. ```python # Grab the account to create the user under account = canvas.get_account(1) user = account.create_user( user={ 'name': 'New User' }, pseudonym={ 'password': 'secure123', 'sis_user_id': 'new_user' } ) ``` -------------------------------- ### Iterate and Print All Courses Source: https://github.com/ucfopen/canvasapi/blob/develop/README.md Loop through a list of courses and print each course object. This is useful for processing multiple courses. ```python >>> for course in courses: print(course) TST101 Test Course 1 (1234567) TST102 Test Course 2 (1234568) TST103 Test Course 3 (1234569) ``` -------------------------------- ### List User Logins Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Fetches and prints the login history for a specific user. This can be helpful for auditing or understanding user access patterns. ```python logins = user.get_user_logins() for login in logins: print(login) ``` -------------------------------- ### Create Assignment with Nested List Parameters Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/keyword-args.md Pass a dictionary for nested parameters where values are lists, such as 'assignment[submission_types][]' and 'assignment[allowed_extensions][]'. This allows specifying multiple submission types or file extensions for an assignment. ```python course.create_assignment( assignment={ 'name': 'Assignment 1', 'submission_types': ['online_text_entry', 'online_upload'], 'allowed_extensions': ['doc', 'docx'] } ) ``` -------------------------------- ### Configure Python Logging for CanvasAPI Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/debugging.md Set up Python's logging module to capture DEBUG level messages from the 'canvasapi' namespace and direct them to standard output. This is essential for viewing detailed library activity. ```python import logging import sys logger = logging.getLogger("canvasapi") handler = logging.StreamHandler(sys.stdout) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setLevel(logging.DEBUG) handler.setFormatter(formatter) logger.addHandler(handler) logger.setLevel(logging.DEBUG) ``` -------------------------------- ### Passing Nested Parameters Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/keyword-args.md Parameters that look like `foo[bar]` in the API documentation should be passed as a dictionary in Python. The dictionary keys correspond to the nested parameter names. ```python account.create_course(course={'name': 'Example Course'}) ``` ```python account.create_course( course={ 'name': 'Example Course', 'course_code': 'TST1234', 'is_public': True } ) ``` ```python account.create_course( course={ 'name': 'Example Course', 'course_code': 'TST1234', 'is_public': True }, enroll_me=True, offer=False ) ``` -------------------------------- ### Create Assignment with Multiple Submission Types Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Creates an assignment that allows students to submit their work using various methods, such as file uploads, text entry, or URLs. ```python new_assignment = course.create_assignment({ 'name': 'Assignment 2', 'submission_types': ['online_upload', 'online_text_entry', 'online_url'] }) ``` -------------------------------- ### Add Grading Standards with Nested Parameters Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/keyword-args.md Use a list of dictionaries to represent nested parameters like 'grading_scheme_entry[][name]' and 'grading_scheme_entry[][value]'. This is useful when creating or updating grading schemes. ```python account.add_grading_standards( title='New Grading Standard', grading_scheme_entry=[ { 'name': 'A', 'value': 90 }, { 'name': 'B', 'value': 80 } ] ) ``` -------------------------------- ### List Courses under an Account Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Retrieves and prints all courses associated with a given Canvas account. This is useful for iterating through courses to perform bulk operations or gather information. ```python courses = account.get_courses() for course in courses: print(course) ``` -------------------------------- ### Using Keyword Arguments for API Calls Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/getting-started.md Pass keyword arguments to API calls to filter or specify parameters, such as enrollment status. ```python # Get all of the active courses a user is currently enrolled in >>> courses = user.get_courses(enrollment_status='active') ``` -------------------------------- ### Slice Course List Source: https://github.com/ucfopen/canvasapi/blob/develop/README.md Extract a subset of courses from a list using Python's slicing syntax. Useful for pagination or selecting a specific range of courses. ```python >>> courses[:2] [TST101 Test Course 1 (1234567), TST102 Test Course 2 (1234568)] ``` -------------------------------- ### Passing List Parameters Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/keyword-args.md For parameters that accept multiple values (e.g., `enrollment_type[]`), pass a Python list to the keyword argument. CanvasAPI automatically formats this for the API. ```python course.get_users(enrollment_type=['teacher', 'student']) ``` ```python course.get_users( enrollment_type=['teacher', 'student'], search_term='John', include=['email'] ) ``` -------------------------------- ### Passing Deep Nested Parameters Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/keyword-args.md For parameters with multiple levels of nesting (e.g., `user[avatar][url]`), use nested dictionaries to represent the structure. This allows for complex object creation or updates. ```python user.edit( user={ 'avatar': { 'url': 'http://example.com/john_avatar.png' } } ) ``` -------------------------------- ### Using Python Datetime Objects for Dates Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/getting-started.md Pass Python datetime objects directly when CanvasAPI expects ISO 8601 formatted strings for date/time parameters like 'start_at' and 'end_at'. ```python from datetime import datetime start_date = datetime(2018, 1, 1, 0, 1) # '2018-01-01T00:01Z' end_date = datetime(2018, 12, 31, 11, 59) # '2018-12-31T11:59Z' course.update( course={ 'start_at': start_date, 'end_at': end_date, } ) ``` -------------------------------- ### Conclude a Course Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Marks a course as concluded in Canvas. This action typically prevents further student enrollments or activity in the course. ```python course.conclude() ``` -------------------------------- ### Change an Assignment’s Submission Type(s) Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Allows modification of the submission types for an assignment. This is useful for controlling how students can submit their work. ```APIDOC ## Change an Assignment’s Submission Type(s) ### Description Allows modification of the submission types for an assignment. This is useful for controlling how students can submit their work. ### Method `assignment.edit()` ### Parameters #### Request Body - **assignment** (object) - Required - An object containing assignment attributes to update. - **submission_types** (list) - Required - A list of strings representing the allowed submission types (e.g., `['on_paper']`). ### Request Example ```python updated_assignment = assignment.edit( assignment={'submission_types': ['on_paper']} ) ``` ### Response #### Success Response Returns the updated assignment object. ### Response Example ```python # Example response structure (actual content may vary) { "id": 12345, "name": "Example Assignment", "submission_types": ["on_paper"] } ``` ``` -------------------------------- ### Automatic Datetime Conversion Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/getting-started.md CanvasAPI automatically converts ISO 8601 datetime strings from the API into Python datetime objects, appending '_date' to the original attribute name. ```python >>> course = canvas.get_course(1) >>> course.start_at '2014-02-11T16:38:00Z' >>> course.start_at_date datetime.datetime(2014, 2, 11, 16, 38, tzinfo=) ``` -------------------------------- ### Delete a Course Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Permanently removes a course from Canvas. Use this with caution as it is irreversible. ```python course.delete() ``` -------------------------------- ### Add Points to All Assignment Scores Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Iterate through all submissions for an assignment and add a specified number of points to each. Handles unscored assignments by treating them as 0. ```python # Set added points as an Int variable added_points = 2 submissions = assignment.get_submissions() for submission in submissions: # Handle an unscored assignment by checking the `score` value if submission.score is not None: score = submission.score + added_points else: # Treat no submission as 0 points score = 0 + added_points submission.edit(submission={'posted_grade': score}) ``` -------------------------------- ### Delete an Assignment Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Removes an assignment from the course. Use with caution as this action is irreversible. ```APIDOC ## Delete an Assignment ### Description Removes an assignment from the course. Use with caution as this action is irreversible. ### Method `assignment.delete()` ### Endpoint N/A (Method call on an assignment object) ### Parameters None ### Request Example ```python assignment.delete() ``` ### Response #### Success Response Typically returns an empty response or a success indicator upon successful deletion. ### Response Example ``` # No specific response body documented, implies success if no error is raised. ``` ``` -------------------------------- ### Change Assignment Submission Type Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Modify an assignment to accept a specific submission type, such as 'on_paper'. ```python updated_assignment = assignment.edit( assignment={'submission_types': ['on_paper']} ) print(updated_assignment) ``` -------------------------------- ### DELETE /api/v1/files/:id Source: https://github.com/ucfopen/canvasapi/blob/develop/tests/fixtures/files.html Removes the specified file from Canvas. ```APIDOC ## DELETE /api/v1/files/:id ### Description Remove the specified file ### Method DELETE ### Endpoint /api/v1/files/:id ``` -------------------------------- ### Update Assignment Score Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Change the score of a specific user's assignment submission. The score should be an integer. ```python # Set `score` to a Int value submission = assignment.get_submission(student_id) submission.edit(submission={'posted_grade':score}) ``` -------------------------------- ### Update an Assignment Submission Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Modifies an existing assignment submission for a student, allowing for score updates or adding points. ```APIDOC ## Update an Assignment Submission ### Description Modifies an existing assignment submission for a student, allowing for score updates or adding points. ### Method `submission.edit()` ### Parameters #### Request Body - **submission** (object) - Required - An object containing submission attributes to update. - **posted_grade** (Integer or Float) - Required - The new score or grade to be posted for the submission. ### Request Example (Change a User’s Assignment Score) ```python # Set `score` to a Int value submission = assignment.get_submission(student_id) submission.edit(submission={'posted_grade':score}) ``` ### Request Example (Add n Points to All Users’ Assignments) ```python # Set added points as an Int variable added_points = 2 submissions = assignment.get_submissions() for submission in submissions: # Handle an unscored assignment by checking the `score` value if submission.score is not None: score = submission.score + added_points else: # Treat no submission as 0 points score = 0 + added_points submission.edit(submission={'posted_grade': score}) ``` ### Response #### Success Response Returns the updated submission object. ### Response Example ```json { "id": 67890, "assignment_id": 12345, "user_id": 54321, "score": 95.0, "posted_grade": "95.0" } ``` ``` -------------------------------- ### Delete an Assignment Source: https://github.com/ucfopen/canvasapi/blob/develop/docs/examples.md Remove an assignment from Canvas using its delete method. Ensure you have the correct assignment object before calling this. ```python assignment.delete() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.