Course Update

Jump to solution
DOGutierrez
Community Member

Hello, 

I am trying to update the end dates for my Canvas courses. I am using the Canvas API module imported to Python. 

Looking at this, I assumed that I would be able to just use the update method. Based on this documentation, I thought that I could do so by passing course{end_at] = [date] as a parameter. So, my code looks like this:

course = canvas.get_course(course_id)

course.update(course[end_at] = [date])

This gives me the error: SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

So, then I thought to try the following:

course.update(end_at = date)

This works without any errors, but doesn't actually change the course end date. I tried passing the date as both a string and DateTime object, but had no success. 

I could really appreciate some help here. I found posts like this. However, I don't understand how to translate the JSON into the appropriate formatting for this update method in the Python module that I am using. I have no previous experience with coding; I am a History teacher and just started learning to be able to work more quickly in Canvas. So, if you are able to help, please just assume that I don't know anything.

0 Likes
1 Solution
themidiman
Community Champion

Success!

Here's my code which updates a course titled 'Canvas Example' to have an end date field set to Dec 1, 2024 in my time zone (your time zone date string may vary))

course_id = <your_course_id>
test_course = canvas.get_course(course_id)
result = test_course.update(course={
        'conclude_at': '2024-12-1T07:00:00.000Z'
    }
)
print(result)
# Prints out Course Title and not a bool as the UCF CanvasAPI documentation has listed 

Note that the documentation for .update(**kwargs) lists that the return type is bool, but my result variable came out as the course title field which is Truthy so you could use that in some sort of logic statement to determine success of the code.

View solution in original post