Not all information is available through GraphQL.
There is no usersConnection under account, but there is under account.coursesConnection. That means that you can get the list of all of the users for a course and do this for all courses within an account, but this is going to be a duplicated list. You can filter on a particular enrollment state for a user, but you cannot filter on types of courses (to just get those that are active).
Here is a GraphQL command that will list the active users for the first 10 courses. Be sure to change the id for the account to match yours.
query listUsers {
account(id: "12345") {
coursesConnection(first: 10) {
nodes {
usersConnection(filter: {enrollmentStates: active}) {
nodes {
_id
name
sortableName
email
sisId
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
If you don't want to filter by enrollment state, then change the usersConnection line to be
usersConnection {
In the response, you will get some pageInfo. If hasNextPage is true, then use the endCursor to make the next call.
My endCursor after that call above was "MTA" so my second call would modify the coursesConnection line to look like this:
coursesConnection(first: 10, after: "MTA") {
The pagination becomes important when you have a lot of courses or a lot of students. For small queries, GraphQL can return results, but it times out after about 30 seconds. This means that you may need to request fewer courses or even restrict the number of users in a course. If you use a first with the usersConnection, then it limits the number of users returned per course, which can be confusing and you would need to return the pageInfo for the usersConnection if you wanted to get all of the users in that course.
On the other hand, using the REST API, you can get an unduplicated list of users within an account with the List users in account endpoint. You will still need to handle pagination as you won't be able to retrieve more than 100 users at a time.