AnsweredAssumed Answered

Adding grade to canvas from an external tool (oauth2)

Question asked by Sion Park on Sep 12, 2018
Latest reply on Sep 13, 2018 by Sion Park

Hi!

 

I was able to get to the point where you get the access token back, however, I'm not able to move further from here. 

I made a quiz and linked to canvas so when students clicks the link it takes them to the page where they have to authorize. Once they click authorize button, it takes them to the quiz. When they submit the quiz, it returns their answers, right answers, and the score. I want to send the score back to canvas so it automatically updates the gradebook. 

I am using http request "PUT" with the access token as a header to update the grade. It gives me 

 

{"id":XXXX,"body":null,"url":null,"grade":null,"score":null,"submitted_at":null,
"assignment_id":102419,"user_id":XXXX,"submission_type":null,"workflow_state":"unsubmitted",
"grade_matches_current_submission":true,"graded_at":null,"grader_id":null,
"attempt":null,"cached_due_date":null,"excused":null,"late_policy_status":null,
"points_deducted":null,"grading_period_id":null,"late":false,"missing":false,
"seconds_late":0,"entered_grade":null,"entered_score":null,
"preview_url":"XXXXXXX?
preview=1&version=0","submission_comments":[],"all_submissions":.......

 

Also, when I send the https request, the url is hard coded because I wasn't able to retrieve the course id and the assignment id where the link was clicked. 

 

httpRequest({
uri: "https://canvas.spu.edu/api/v1/courses/00000/assignmets/000000/subimissions" + userId,
method: 'PUT',
headers:{
// "Content-Type": "application/x-www-form-urlencoded",
"Authorization": " Bearer " + accessToken
},
json: {
'submission[posted_grade]': "10",
"workflow_state": "submitted"
}
},function (er,res,body){
if (!er && res.statusCode == 200) {
console.log("entered");
console.log(body);
response.send(body);
}
})

 

In short, could I get help with using access token (received through oauth2) to send the grade back to canvas from an external tool??

 

Thank you!! 

Outcomes