Add comments (text) via Python API

Jump to solution
rashmi_banthia
Community Novice

Hello, 

I am trying to upload a string as a comment for one student, one submission using Python API. (I have Python 3) I am able to upload the file but not the string. 

Here's the code I have so far and it works for uploading file. I tried submission.edit() but couldn't get it to work. 

API_URL = 'https://canvas api url' ## Canvas API URL
API_KEY = "canvas api key" ## Canvas API key
COURSE_ID = 1234 #COURSEID
ASSIGNMENT_ID = 123456 #Assignment ID

canvas = Canvas(API_URL, API_KEY)
course = canvas.get_course(COURSE_ID)
assignment = course.get_assignment(ASSIGNMENT_ID)

submissionuser_234581 = assignment.get_submission(user = 12345)
submissionuser_234581.upload_comment(file='sample.txt')

Any help much appreciated. (If I have posted in wrong forum please let me know - first time post here)

0 Likes
1 Solution
jaspervdh96
Community Novice

Took me a long time as well, but this should work! This can't be combined with the file comment, so that will create two seperate comments.

submission.edit(submission={comment={'text_comment':'Write your comment here'})

View solution in original post