Canvas is experiencing issues due to an ongoing AWS incident. Follow the status at AWS Health Dashboard and Instructure Status Page
Found this content helpful? Log in or sign up to leave a like!
Hi,
Recently the Grade Posting Policy has been added to the New Gradebook:
Currently the default option is Automatically Post Grades, but we want to have all our courses set to Manually Post Grades. We would like to do this using the API and it seems this is possible using the GraphQL API. I have been trying to understand how this works using the following resources:
I'm using Postman to experiment with the GraphQL API and managed to read data. To change the Post Policy of an assignment I came up with the following code:
POST {{canvas_url}}/api/graphql
GRAPHQL VARIABLES
{
"canvas_course_id": 26163
}
QUERY
mutation ($canvas_course_id: ID!) {
setCoursePostPolicy(objects: [{
courseId:$canvas_course_id,
postManually:true
}]) {
errors
postPolicy
}
}
I keep on getting the error "Field 'setCoursePostPolicy' is missing required arguments: input" and I don't know why.
What do I need to change to make it work?
Solved! Go to Solution.
Have you tried this through the /graphiql endpoint of Canvas? When I go there and click on mutation and click on setCoursePostPolicy, it comes up with this:
mutation MyMutation {
__typename
setCoursePostPolicy(input: {courseId: "2517260", postManually: true})
}
That didn't work, it complained about not having some required results, so I modified it to return the error and postPolicy like you had (sort of)
mutation MyMutation {
__typename
setCoursePostPolicy(input: {courseId: "2517260", postManually: true}) {
errors {
attribute
message
}
postPolicy {
postManually
}
}
}
This is what it looks like in the Explorer
And this is what the result comes back as
{
"data": {
"__typename": "Mutation",
"setCoursePostPolicy": {
"errors": null,
"postPolicy": {
"postManually": true
}
}
}
}
Here's what it shows in my course gradebook settings
I changed the true to false and now I have this
\
It looks like you know how to make the call with the REST API, so I'll stop here. I haven't actually accomplished that yet, only doing things through the /graphiql interface.
Have you tried this through the /graphiql endpoint of Canvas? When I go there and click on mutation and click on setCoursePostPolicy, it comes up with this:
mutation MyMutation {
__typename
setCoursePostPolicy(input: {courseId: "2517260", postManually: true})
}
That didn't work, it complained about not having some required results, so I modified it to return the error and postPolicy like you had (sort of)
mutation MyMutation {
__typename
setCoursePostPolicy(input: {courseId: "2517260", postManually: true}) {
errors {
attribute
message
}
postPolicy {
postManually
}
}
}
This is what it looks like in the Explorer
And this is what the result comes back as
{
"data": {
"__typename": "Mutation",
"setCoursePostPolicy": {
"errors": null,
"postPolicy": {
"postManually": true
}
}
}
}
Here's what it shows in my course gradebook settings
I changed the true to false and now I have this
\
It looks like you know how to make the call with the REST API, so I'll stop here. I haven't actually accomplished that yet, only doing things through the /graphiql interface.
Hi @James , thank you for your help with this. I couldn't see your reply because it was not yet visible as it was moderated. In the mean time I figured it out exactly as you explained it after learning about the /graphiql endpoint and wrote my reply below (which was also under moderation for a full day).
It appears that there is a Live API for GraphQL for each Canvas instance: your.instructure.com/graphiql (note the 'i' between "graph" and "ql"). Now I was able to select the items I needed:
It generated:
mutation MyMutation {
__typename
setCoursePostPolicy(input: {courseId: "26163", postManually: true}) {
errors {
attribute
message
}
postPolicy {
_id
postManually
}
}
}
Running it returned the following
{
"data": {
"__typename": "Mutation",
"setCoursePostPolicy": {
"errors": null,
"postPolicy": {
"_id": "100874",
"postManually": true
}
}
}
}
In Postman I created some variables so I could use a runner to apply these settings on multiple courses using a csv containing the Course IDs and the required boolean variable:
GRAPHQL VARIABLES
{
"canvas_course_id": 26163,
"course_post_grades_manually": false
}
QUERY
mutation ($canvas_course_id: ID!, $course_post_grades_manually: Boolean!) {
__typename
setCoursePostPolicy(input: {courseId: $canvas_course_id, postManually: $course_post_grades_manually}) {
errors {
attribute
message
}
postPolicy {
_id
postManually
}
}
}
Making these changes per assignment using setAssignmentPostPolicy should be the same, I will try that next.
@stelpstra and @James , please know that one of the interesting baked-in quirks of this platform is that posts containing a large amount of code are automatically sent to the Moderation queue—and although we strive to release those posts from the queue as quickly as possible, we don't always get to them as promptly as one would hope. Sorry about that.
Hello all, thanks for the info
Is there anyway of doing multiple courses at once? I.e. if i had a whole account of course ids do them all at once?
Thanks
Each course requires its own API call; there is no batch API call here (there is a limited number of batch API calls at all).
You can write a script that takes a list of courses to execute this for and run the script once. That's kind of like doing them all at once, but probably not what you wanted.
Thanks for the info, i'll see what i can do with a script, the trouble is as far as i can tell you cannot do this via the normal API so this seems like the only option.
Hello i have figured out a way of doing this using aliases and a script that generates multiple aliases from course IDs, simply you end up with something like the below:
mutation MyMutation {
course000: setCoursePostPolicy(input: {postManually: true, courseId:"ID1"})
{
errors {
attribute
message
}
}
course001: setCoursePostPolicy(input: {postManually: true, courseId:"ID2"})
{
errors {
attribute
message
}
}
course002: setCoursePostPolicy(input: {postManually: true, courseId:"ID3"})
{
errors {
attribute
message
}
}
}
You can then create this in a mutation on the graph ql page for your institution and run it. I tested at about 75 each time and it seemed to cope fine, with the request taking about 1-2 seconds, i wonder if you try to do hundreds whether you may face an issue.
Thanks
You can automate GraphQL calls through the REST API. This page explains how: GraphQL API - Canvas LMS REST API Documentation
To 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