The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December.
Read our blog post for more info about this change.
Found this content helpful? Log in or sign up to leave a like!
How do I retrieve the submission history for an assignments with GraphQL? In the REST API you need to manually specify to include submission_history. This is one of many fields that is seemingly inaccessible, is there any plans to bring the GraphQL API to feature parity?
/api/v1/courses/:courseId/students/submissions?include[]=submission_history
Thanks!
Solved! Go to Solution.
By online_quiz, you probably mean Classic Quiz. Support for Classic Quizzes in GraphQL is extremely limited. One of the few things dealing with Classic Quizzes in GraphQL is whether an assignment is a quiz and what the quiz ID is. That's about it. Generally speaking, if you want anything related to Classic Quizzes, you'll want to use the REST API rather than GraphQL.
On the back-end, multiple assignment submissions are handled by the submission_history table, which is what GraphQL is linking up against. However, for Classic Quizzes, they're part of the quiz_submission_history table. That goes to the lack of support for Classic Quizzes in GraphQL. Since Canvas wants all of us to stop using Classic Quizzes and they've stopped any real development on them, do not look for that support to be added to GraphQL.
Not all information available through the REST API is available through GraphQL and vice versa. There are four main sources of information I use and the same is true for all of them: REST API, GraphQL, Canvas Data 2, and Live Events. Each of them has a target in mind. GraphQL was designed to be quick lookups and while some functionality was ported from the REST API, not all of it is there. There was a comment at one point that if you were missing something, to request it, but there's no guarantee it will get there.
That warning out of the way, you can use the submissionHistoriesConnection under a Submissions property to get the Submissions History. Here's an example query that gets all submissions that were made for one of my classes since today (obviously today becomes outdated very quickly).
query submissionHistoryCourse {
course(id: "4014893") {
submissionsConnection(filter: {gradedSince: "2024-09-27T00:00:00Z"}) {
nodes {
_id
assignmentId
submissionHistoriesConnection(filter: {includeCurrentSubmission: true}) {
nodes {
attempt
score
}
}
}
}
}
}
You can also get all of the submissions for a single assignment with more flexibility in the filtering.
query submissionHistoryAssignment {
assignment(id: "45956245") {
submissionsConnection(filter: {enrollmentTypes: StudentEnrollment}) {
nodes {
_id
submissionHistoriesConnection {
nodes {
attempt
score
}
}
}
}
}
}
Likewise, you can get the submission history for an individual submission.
A potential issue may be what you want from the submission histories. Not all information from the REST API is there (hence my warning at the start). With the submission_history from the REST API, I can get the answers given for Classic Quizzes. That is not available for the REST API. However, scores, rubrics, and a lot of other stuff is there.
@James
Appreciate the reply. When I call the REST API with include[]=submission_history, I get the submission history for each assignment. However when I query the submission history with the submissionsHistoryConnection via the GraphQL API, I get only the highest scoring submission. I need all the submissions, not just the most recent one. Also the submissionsHistory connection appears to just return the same submission (unless includeCurrentSubmission is set to false, in which case I just get an empty array). Its not a permissions issue, so my guess is that field is just broken?
Are you able to retrieve submission history via the connection?
When I was responding, I used the code I provided for testing. There were some cases where I received multiple items in the submission history through GraphQL.
Here is one of the responses.
{
"_id":"747433764",
"submissionHistoriesConnection":{
"nodes":[
{
"attempt":1,
"score":null
},
{
"attempt":2,
"score":10.5
}
]
}
}
It may be specific to the type of assignment. This was from a file-submission assignment.
On another note, Canvas just announced today that they are changing the behavior of GraphQL in a "no-big deal" way (my paraphrase of their sentiment). That's what I've been busy looking into between my two responses to you. It's a major breaking change for me.
Starting October 9, they are no longer going to return unlimited results. The default will be 20 with a maximum of 100. It won't return an error or any notice if you have more than 20 results, you just won't get them all. That has the potential to break a lot of stuff that assume we're getting all of the results at once. For example, one of my applications downloads all of the grades and puts zeros for LTI assignments that haven't been turned in on time. Until I get that fixed, every student past the first 20 will start getting 0's.
It looks like we're going to have to implement pagination for these simple requests to get results quickly. That means that GraphQL may no longer provide the benefit that it once did.
There are some of us commenting on the announcement but I doubt it will make an impact before October 9.
@James
You say: "It may be specific to the type of assignment. This was from a file-submission assignment." Do you have any more details on this? Mine are of type "online_quiz".
Heres what mine look like using a student token (as well as a teacher):
submission(id: "626243234") {
submissionHistoriesConnection {
nodes {
attempt
score
}
}
}
{
"data": {
"submission": {
"submissionHistoriesConnection": {
"nodes": [
{
"attempt": 4,
"score": 18.5
}
]
}
}
}
}
My application uses pagination already, but I am sorry that your application is breaking. Its probably for the best to protect against large queries though.
By online_quiz, you probably mean Classic Quiz. Support for Classic Quizzes in GraphQL is extremely limited. One of the few things dealing with Classic Quizzes in GraphQL is whether an assignment is a quiz and what the quiz ID is. That's about it. Generally speaking, if you want anything related to Classic Quizzes, you'll want to use the REST API rather than GraphQL.
On the back-end, multiple assignment submissions are handled by the submission_history table, which is what GraphQL is linking up against. However, for Classic Quizzes, they're part of the quiz_submission_history table. That goes to the lack of support for Classic Quizzes in GraphQL. Since Canvas wants all of us to stop using Classic Quizzes and they've stopped any real development on them, do not look for that support to be added to GraphQL.
@James
The Classic vs New Quizzes answer was correct, but now I am just confused about the data stored in the submissions_history table. When I query the REST API for submissions for a specific student's assignment, I get this:
{
"id": 110513068,
"score": 3.0,
"submitted_at": "2024-09-30T23:43:52Z",
"assignment_id": 2257438,
"user_id": 50643,
"submission_type": "basic_lti_launch",
"workflow_state": "graded",
"attempt": 6,
"submission_history": [
{
"id": 110513068,
"score": 10.0,
"submitted_at": "2024-09-30T23:38:57Z",
"assignment_id": 2257438,
"user_id": 50643,
"grade_matches_current_submission": true,
},
{
"id": 110513068,
"score": 3.0,
"submitted_at": "2024-09-30T23:43:52Z",
"assignment_id": 2257438,
"user_id": 50643,
"grade_matches_current_submission": true,
}
]
}
While the API matches the expected Canvas submissions for our test student, how is this attempt #6?
When I query GraphQL for the same data:
{
"submissionsConnection": {
"nodes": [
{
"_id": "110513068",
"attempt": 6,
"score": 3.0,
"submittedAt": "2024-09-30T17:43:52-06:00",
"submissionStatus": "submitted",
"submissionHistoriesConnection": {
"nodes": [
{
"attempt": 5,
"score": 10.0,
"submittedAt": "2024-09-30T17:38:57-06:00",
"submissionStatus": "submitted"
},
{
"attempt": 3,
"score": 10.0,
"submittedAt": "2024-09-30T17:38:57-06:00",
"submissionStatus": "submitted"
},
{
"attempt": 1,
"score": 10.0,
"submittedAt": "2024-09-30T17:38:57-06:00",
"submissionStatus": "submitted"
},
{
"attempt": 6,
"score": 3.0,
"submittedAt": "2024-09-30T17:43:52-06:00",
"submissionStatus": "submitted"
},
{
"attempt": 4,
"score": 10.0,
"submittedAt": "2024-09-30T17:43:52-06:00",
"submissionStatus": "submitted"
}
],
}
}
]
}
}
It appears submission history is doubling up (based on submitted at) and also where is attempt #2? Do you have any idea what might be happening here?
It appears it used to work, not sure if it still does: https://github.com/instructure/canvas-lms/commit/a3790f177c7a2b674587a86a854b88d9ceaa2899
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in