Filter Course Enrollment API results

Jump to solution
Community Member

Is it possible to filter an API get to only return the ID of students where the final grade is not null?

1 Solution
Community Champion


Yes, but probably not the way you mean.

You can filter any response that you get to look for null final grades and remove them. That is, after you have received the results, you can filter.

There may be some filtering you can do ahead of time to help, but it is very limited. Specifically, you can specify the state and enrollment type. If you only look for active students, you have a better chance of not getting a null final grade.

You may want to add completed, depending on how your school handles enrollments. Alternatively, you could not filter at all.

Here is some GraphQL to get the final grades.

query MyQuery($courseId: ID!) {
  course(id: $courseId) {
    enrollmentsConnection(filter: {states: active, types: StudentEnrollment}) {
      nodes {
        grades {
        user {

You would call this with variables indicating the courseID you want to include the results for. For example, it might look something like this.

{ "courseId": 3903130 }


Note that through the GraphQL explorer (found by adding /graphiql to the end of your dashboard URL), you can only add one state at a time. However, valid GraphQL allows an array. That enrollmentsConnection could look like this:

enrollmentsConnection(filter: {states: [active,completed,deleted], types: StudentEnrollment})

From this, you will get an object that starts like this (the IDs are bogus):

  "data": {
    "course": {
      "enrollmentsConnection": {
        "nodes": [
            "grades": {
              "finalScore": 92.05,
              "finalGrade": "A-"
            "user": {
              "_id": "12345678",
              "sisId": "987654",
              "sortableName": "Jones, James"

So, if you want the people who have a non-null final grade and assuming the results are stored in a variable called response, then you could use

const finalGrades = => e.grades.finalGrade !== null);


View solution in original post