cancel
Showing results for 
Search instead for 
Did you mean: 
abgupta
Community Member

Add grade using canvas submission API

Jump to solution

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

Tags (1)
1 Solution

Accepted Solutions
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

2 Replies
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

Hi Colin,

That resolved the issue.

Thanks a lot!

Best,

Abhishek Gupta