cancel
Showing results for 
Search instead for 
Did you mean: 
b_willems
Surveyor

GraphQL query for updating course post policies

Hi Developers!

We are trying to update a course’s post policies with GraphQL. We managed to create them but are stuck when trying to update existing ones.

This is the use case: The API sets a course’s Post Policy for Grades to manual. To make sure that teachers don’t change it back in the GUI, we check and update the Post Policy to change back to ‘Manually post grades’.

Could anyone help with an example query for updating Post Policies?

Thanks! 

Barbara

Labels (1)
2 Replies
raj_veeravalli
Learner

Wrote something real quick to do this. Following code uses UCF canvasapi and sgqlc module. Sample code, in case someone wants to use it.

You may need to size this to your needs. I have a small tenant with only 80 something courses and there are no issues.

To set course status ...

# gql setup
endpoint = HTTPEndpoint(url=url, base_headers=header)
mutation_op = Operation(schema.Mutation)
# control logic
alias_count = 0
courses = account.get_courses(enrollment_term_id=enrollment_term_id)
for course in courses:
    course_id = course.id
    query_alias = "gql" + str(alias_count).zfill(3)
    alias_count = alias_count + 1
    gql_mutate = mutation_op.set_course_post_policy(
        input=schema.SetCoursePostPolicyInput(
            course_id=course_id,
            post_manually=True
        ),
        __alias__=query_alias
    )
# print(mutation_op)
endpoint(mutation_op)

To retrieve data use a query instead of mutation.

You can also request additional fields in your mutation query for error handling, retries, logging etc.