Add grade using canvas submission API

Jump to solution
abgupta
Community Novice

Hi All,

I am Abhishek Gupta, a TA at UC Davis.

I am trying to build an application that update grades for students for a particular assignment.

I am was able to query student id's.

However, I have trouble updating the grades. I have looked at the Submissions - Canvas LMS REST API Documentation 

and tried it. My request returns a 200 code and a JSON object but the grade is not updated.

Below is the python code for updating grade for a single student for an assignment:


GRADE_URL = 'https://canvas.ucdavis.edu/api/v1/courses/' + course_id + '/assignments/' + assignment_id + '/submissions/' + user_id
#make the form data
data = { 'submission':{
                                    'posted_grade': 8.0
                                   }
             }
#make the PUT request

userGrade = requests.put(GRADE_URL, headers = self.headers, data = data)

Any help in this regard will be much appreciated!#post grades

1 Solution
ColinMurtaugh
Community Champion

Hi Abhishek --

I think the issue is that the requests module is form-encoding your data by default rather than sending it as JSON-encoded data.  To make the form-encoded PUT request work, you'd need to change your code to something like:

data = {

    'submission[posted_grade]': 8.0
}

Alternatively, you could have the requests module send JSON-encoded data like this:

userGrade = requests.put(GRADE_URL, headers=self.headers, json=data)

Hope this is helpful!

--Colin

View solution in original post