cancel
Showing results for 
Search instead for 
Did you mean: 
dylanrainbolt
Community Member

Using Python canvasapi module to find who hasn’t submitted assignment

Hello, everybody,

Introduction:

My school requires us teachers to send out emails to parents and fill out a Google form when a student doesn’t turn in their homework. Naturally, I’ve been using Python to stream line this process to save myself time. What I’ve been doing for the past year is downloading the grade book from Canvas manually and then importing the file in Python and then having Python send emails to parents and fill out the additional documentation for students if they have received a zero for an assignment. This really helps cutting down the time; however, I want to streamline the process even further.

 

What I want to be able to do:

in the long run I really want to be able to use the Python canvasapi module to find what student hasn’t submitted a certain assignment that I enter in the program just through the api (so that I don’t have to download and read the grade book file).

Labels (3)
3 Replies
James
Community Champion

@dylanrainbolt 

I don't use the Python CanvasAPI program, but it just pulls the information from the Canvas API, so knowing where to get it from the Canvas API should help.

The entries in the gradebook come from the Submissions API. If you are looking for a single assignment at a time, you can use the List assignment submissions endpoint. I prefer the flexibility of the List submissions for multiple assignments endpoint and specify student_ids[]=all to get all current students for the specified assignments (or the entire gradebook). The include[]=user will give you information about the student to make it helpful. One caveat, if you are using quizzes or discussions, make sure you give the assignment ID and not the quiz ID or discussion ID.

This can also be done using the GraphQL interface. This is the way Canvas is wanting to push people instead of the REST API mentioned above. I do not know if the Python library supports GraphQL, but ultimately, the GraphQL request is made through the REST API and you can typically get all results in a single call rather than having to worry about pagination (if you have more than 100 items returned [default is 10, but you can use per_page=100 to get more).

The problem is that neither one of those allows filtering, despite that being one of the great advantages to GraphQL. That means that you will need to download all of the results and then filter to see which ones are missing.

Here's an example GraphQL query. You can add /graphiql to your Canvas dashboard URL and test this and play around with the information that you need. Replace the assignment id with yours.

query missingAssignments {
  assignment(id: "12345678") {
    _id
    name
    submissionsConnection {
      nodes {
        missing
        user {
          _id
          sortableName
          email
          sisId
        }
      }
    }
  }
}

Then you're going to filter on missing:true to find the students who haven't submitted the assignment. I included user._id to get the Canvas ID for the user and sisID to get the SIS ID for the student. The SIS ID is not visisble to everyone, so I wanted another ID that I could use. It may be that email is sufficient for your needs.

Note that this particular request does support filtering (most do not), but missing is not an option for filtering (late is). You might be tempted to filter on an unsubmitted state, but that is not the same thing as missing.

jerry_nguyen
Community Participant

@dylanrainbolt 

Further on from James's solution. If you have multiple courses, you can also run a GraphQL query on "allCourses" to get raw data then use a loop to filter it

  allCourses {
    name
    _id
    submissionsConnection(filter: {states: submitted}) {
      nodes {
        gradingStatus
        submissionStatus
        submittedAt
        state
        assignment {
          _id
          name
        }
        user {
          _id
          name
          sisId
          email
          enrollments {
            state
            course {
              _id
            }
          }
        }
      }
    }
  }
}

 

bbennett2
Community Champion

The Python library added GraphQL POST support in June 2020. You should be able to use it to make GraphQL queries.

Relevant PR to the project

Documentation on using GraphQL