cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
rashmi_banthia
Community Member

Add comments (text) via Python API

Jump to solution

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 Kudos
1 Solution

Accepted Solutions
jaspervdh96
Community Member

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

2 Replies
jaspervdh96
Community Member

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

Thank you so much for your solution! I have been looking everywhere to find a working example of how to set the comments in student's submission.

I do not know if the canvasapi changed but I had to adapt your row to the following statement to work:

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