API call to post a submission
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have setup all the assignments of a course to be posted manually, so that students can only see their grades after the assignment of all students have been graded for everyone. That means that after I grade, I have to go to the gradebook in Canvas (see pic)
I would like to know if there is an API call to post the submissions once all student's assignments are graded.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are several reasons why this might not work, but it's hard to pinpoint without additional information.
Where did you get your information about how to post grades using this API call? I don't see post_manually in the API documentation. What is URL and why do you have ITEMS_PER_PAGE on a PUT statement?
Since I don't know the answers to those questions, I cannot say for sure why your request doesn't work. Since I didn't see anything about post_manually in the documentation, I went to the next best source (sometimes better) -- clicking something in Canvas and then watching what it sends to the server.
When you post the grades through the gradebook, Canvas makes a call to the GraphQL interface, not the REST API. That is POST /api/graphql with a mutation query. It needs to be POST, not PUT.
Here is the query that it uses. This is a string in the actual object.
mutation ($assignmentId: ID!, $gradedOnly: Boolean) {
postAssignmentGrades(input: {assignmentId: $assignmentId, gradedOnly: $gradedOnly}) {
progress {
_id
state
__typename
}
__typename
}
}
Along with this, you need to include a variables portion that specifies the assignmentID and the value of gradedOnly.
variables: {assignmentId":"13857975","gradedOnly":false}
The mutation is specified as the query property in an object and it is a string.
GraphQL statements have a special format that must be met. You cannot just send data as you do with a REST API query. It needs a query property and possibly a variables section. The basic format looks like this (obviously this is not valid):
{
"query" : "GraphQL statement as a string",
"variables" : { variables as an object }
}
The query needs to start off with query for getting data or mutation for changing data. Since you're trying to change something, you would need mutation.
Here's the whole thing that Canvas sent (operationName is optional) for this particular request.
{
"operationName": null,
"variables": {
"assignmentId": "13857975",
"gradedOnly": false
},
"query": "mutation ($assignmentId: ID!, $gradedOnly: Boolean) { postAssignmentGrades(input: {assignmentId: $assignmentId, gradedOnly: $gradedOnly}) { progress { _id state __typename} __typename }}"
}
It may be possible to use your post_manually, except that post_manually isn't likely to be used in GraphQL as it uses camelCase (postManually), I didn't go in and explore the graphiql interface and documentation too much.
What I did was open up the developer tools in the browser and then click the Post Grades button and look at what Canvas sent as a request. That's a very useful trick when you cannot make sense out of the documentation.
I did verify that you could drop the progress portion of the mutation, but it doesn't work without the __typename. In other words, the minimal mutation for the query property would be
mutation ($assignmentId: ID!, $gradedOnly: Boolean) {
postAssignmentGrades(input: {assignmentId: $assignmentId, gradedOnly: $gradedOnly}) {
__typename
}
}
See the GraphQL instructions in the API documentation for more information on sending GraphQL queries.