The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December. Read our blog post for more info about this change.
Hi There
Is it possible to make the List Enrollments (https://canvas.instructure.com/doc/api/enrollments.html#method.enrollments_api.index) API call without receiving "user" data in the response body?
Here is an example request:
https://qwickly.instructure.com/api/v1/courses/248/enrollments?state%5B%5D=invited&state%5B%5D=activ...
Here is an example response from the listed request:
{'course_id': 248, 'id': 2165, 'user_id': 570, 'course_section_id': 266, 'root_account_id': 1, 'type': 'StudentEnrollment', 'created_at': '2021-11-19T15:37:37Z', 'updated_at': '2021-12-07T20:26:48Z', 'associated_user_id': None, 'start_at': None, 'end_at': None, 'limit_privileges_to_course_section': True, 'enrollment_state': 'active', 'role': 'StudentEnrollment', 'role_id': 3, 'last_activity_at': None, 'last_attended_at': None, 'total_activity_time': 0, 'grades': {'html_url': 'https://qwickly.instructure.com/courses/248/grades/570', 'current_grade': None, 'current_score': None, 'final_grade': None, 'final_score': None, 'unposted_current_score': None, 'unposted_current_grade': None, 'unposted_final_score': None, 'unposted_final_grade': None}, 'sis_account_id': None, 'sis_course_id': None, 'course_integration_id': None, 'sis_section_id': None, 'section_integration_id': None, 'sis_user_id': '472042', 'html_url': 'https://qwickly.instructure.com/courses/248/users/570', 'user': {'id': 570, 'name': 'David Abraham', 'created_at': '2021-11-17T09:24:57-07:00', 'sortable_name': 'Abraham, David', 'short_name': 'David Abraham', 'sis_user_id': '472042', 'integration_id': None, 'login_id': 'david.abraham@goqwickly.com'}}
Our tool is designed to load enrollments in a course, and subsequently load the data of the users individually. We want to follow a workflow where user data is not returned with each enrollment data since we may have already saved certain user data in the past and thus we can save time by not getting user data with each request.
This is causing API load time issues for clients who have common classe sizes well over 500+ users.
Ideally the enrollments call would simply return the enrollment data, course_id and user_id. We would then be able to see if we are missing any user data for any of the user_ids and make separate Get User requests to get those data pieces.
Solved! Go to Solution.
You can't change the structure of data returned by API. However, you can try GraphQL which allows you to select only the fields you want to pull.
The GraphQL playground is available at youracademy.instructure.com/graphiql. You can try the following query which returns all student enrollment within a course and its status
query MyQuery {
course(id: "49") {
enrollmentsConnection(filter: {types: StudentEnrollment}) {
nodes {
user {
_id
}
state
}
}
}
}
You can also post this query to the GraphQL endpoint, take a look at the document here: https://canvas.instructure.com/doc/api/file.graphql.html
You can't change the structure of data returned by API. However, you can try GraphQL which allows you to select only the fields you want to pull.
The GraphQL playground is available at youracademy.instructure.com/graphiql. You can try the following query which returns all student enrollment within a course and its status
query MyQuery {
course(id: "49") {
enrollmentsConnection(filter: {types: StudentEnrollment}) {
nodes {
user {
_id
}
state
}
}
}
}
You can also post this query to the GraphQL endpoint, take a look at the document here: https://canvas.instructure.com/doc/api/file.graphql.html
Hi Jerry
Thanks for pointing this resource out! This certainly seems to do the task I require of it!
However, now I am getting an issue when trying to paginate my graphQL request. I have an endCursor and hasNextPage=True and following the canvas documentation about pagination (https://canvas.instructure.com/doc/api/file.graphql.html), I have to update my query with an "after" parameter in the query, so now my query for the next page looks like this:
query CourseEnrollmentInfo {
course(id: 248) {
_id
enrollmentsConnection(first: 50, after: "NTA") {
nodes {
lastActivityAt
state
type
section {
_id
}
user {
_id
sisId
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
However, making this request to the /api/graphql endpoint using the same token is causing a ConnectionError which states "Max retries exceeded with url: /api/graphql"
Any idea why the new page request isn't working? When I increase the "first" parameter to a much higher number, I dont need to run the next page request, but we won't know what the max number would always be and I would like to make sure pagination is handled correctly.
I never ran into pagination issues with GraphQL so I'm not sure, however, as far as I know, GraphQL should return all results in one request (Our largest course has 1000 students).
Did you try the query through the GraphiQL playground?
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in
This discussion post is outdated and has been archived. Please use the Community question forums and official documentation for the most current and accurate information.