How to read and change Course Post Policy of the New Gradebook with GraphQL

Jump to solution
stelpstra
Community Champion

Hi,

Recently the Grade Posting Policy has been added to the New Gradebook:

https://community.canvaslms.com/docs/DOC-16958-canvas-release-notes-2019-07-13#jive_content_id_Grade... 

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?

Labels (1)
1 Solution
James
Community Champion

 @stelpstra  

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

320799_pastedImage_3.png

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

320800_pastedImage_4.png

I changed the true to false and now I have this

320801_pastedImage_5.png\

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.

View solution in original post