Canvas LMS API - "What-If Scores"

Jump to solution
jpatel05
Community Member

As the subject of the post indicates, I want to know if it's possible to access the "What-If" scores from the API. I've looked this the documentation, but I haven't see any mention of these scores or how to access them. However, I feel that it's very possible that I missed it, since the data for these "What-If" scores seems to be stored somewhere that isn't local, however, I haven't been able to figure out where. 

If anyone could provide guidance on the correct approach to retrieve these scores, I would greatly appreciate it. Please note that any necessary API calls will be made from the user's end, so there shouldn't be any permission issues.

I've also attached a picture of the 'What-If' scores I'm referring to, to eliminate any confusion.

0 Likes
1 Solution
James
Community Champion

@jpatel05 

It's not in the API documentation because the REST API doesn't support it. It would be under the submissions API if it was there.

 

The what-if grades are provided as part of the HTML that is sent with the grades page. They are not loaded through an XHR/Fetch request.

When a student changes the what-if grade, a POST is made to an internal (non-API) route for the submissions to <instance>/courses/:course_id/assignments/:assignment_id/submissions/:user_id.

The response from that call includes a property for "student_entered_score", which is the what-if score the student typed.

Sometimes, there is a corresponding API requests, but most often, an internal request means that it is calling something not supported by the API. The ability to create a rubric used to be internal-only (when I wrote my script to import a rubric from a spreadsheet), but then Canvas added an API call for it. Another check is whether the Canvas Student App can change what-if grades. If so, then there's a high probability that there is an API call for it. I do not see the ability to change what-if grades from the Canvas Student App.

As for the API version of an internal route, there is a Get a single submission that follows the same path, but with the api/v1 in front of it. However, that does endpoint does not return the student_entered_score or the value entered under a different name. There is also a PUT to the same API path, but it does not list the student_entered_score since that's not something that other people can do, it's something only the user can do.

Sometimes, there are non-documented parameters. The routine to update the score is found in the /app/controllers/submissions_base_controller.rb file. The submissions API calls /app/controllers/submissions_api_controller.rb. 

If you try a POST to the API version of the path, it comes back with a 404 Not Found status. A PUT returns an object, but does not return the what-if grade; nor does it update the grade.

With the REST API, it does not look like you're going to get the what-if grades.

The good news, if any, is that you did a thorough job of looking and didn't overlook something simple.

 

Now that we know it's not in the REST API, let's talk about where it is.

There is another API -- the GraphQL one. If you add /graphiql to the end of your dashboard URL, you can try this.

query whatIfGrades($courseId: ID!, $studentId: [ID!]) {
  course(id: $courseId) {
    submissionsConnection(studentIds: $studentId) {
      nodes {
        assignment {
          _id
          name
        }
        score
        studentEnteredScore
      }
    }
  }
}

At the bottom, there are Query Variables, you will need to include a JSON object. Change these numbers to match your data.

{
  "courseId": 3592387,
  "studentId": 1234
}

The "studentId" is a single value or an array, so you could use [ 1234, 1235 ] if you wanted to get more than one user's grades.

If you want to get the grades for all students in a class, you could pass an empty array [ ] for the studentId, but then you would want to add some extra information to tell who the student was.

This is through the GraphQL API through the web interface, which brings us back to the problem of getting it through the REST API. Thankfully, you can make GraphQL queries through the REST API.

If you're looking to determine this for a student in multiple courses, you will need to make the call for each course.

 

The information is also available in Canvas Data 2. In the canvas__submissions table, there is a student_entered_score.

View solution in original post