[ARCHIVED] API PUT request does nothing

bunzejj
Community Explorer

I'm trying to use the Canvas API through Google Apps Script to send students scores in for the classes I teach. Currently, I'm attempting to use the "Grade or comment on a submission" documented here. I know that my URL is set up correctly as I can test out API calls using Canvas' live API feature. The response code comes back as 200 however the student's grade remains unchanged.

Here's the code I'm using:

 

 

 

      var url = "https://hsccsd.instructure.com:443/api/v1/courses/"+getcourseid()+"/assignments/"+assignmentid+"/submissions/"+studentid;
      var payload = JSON.stringify({
        "score": 7
      });
      var headers = {
        "Authorization": "Bearer " + getcanvasaccesstoken()
      };
      var options = {
        "contentType": "application/json",
        "method": "put",
        "headers": headers,
        "payload": payload, 
        "muteHttpExceptions" : true,
      };

  var apiresponse = UrlFetchApp.fetch(url,options);

 

 

 

 

The request (using UrlFetchApp.getRequest) gives me:

 

 

 

{method=put, 
useIntranet=false, 
followRedirects=true, 
headers={Authorization=Bearer <token}, 
contentType=application/json, validateHttpsCertificates=true,
url=https://hsccsd.instructure.com:443/api/v1/courses/6656/assignments/3497414/submissions/60144, 
payload={"score":7}}

 

 

 

 

Again, the response I receive back shows no change in the "score" parameter. I'm not sure if there is maybe an issue with how the payload is formatted. This works through the Canvas Live API but it doesn't show me how a similar request should be formatted only the url.

Labels (2)
0 Likes