cancel
Showing results for 
Search instead for 
Did you mean: 
dtod
Community Contributor

Identify concluded enrollments

Trying to identify concluded enrollments within a course in the API (because the GUI doesn't seem to help either). I feel like I must be missing something.

/api/v1/courses/[ID]/enrollments doesn't seem to do it.

0 Kudos
9 Replies
robotcars
Community Champion

There is a state parameter.

Enrollments - Canvas LMS REST API Documentation 

var url = new URL("https://*.instructure.com/api/v1/courses/123/enrollments"),
opts = {
state: 'completed'
}
Object.keys(opts).forEach(key => url.searchParams.append(key, opts[key]));
fetch(url, {
method: 'GET',
headers: {
'accept': 'application/json',
'content-type': 'application/json'
}
})
.then(res => res.json())
.then(json => console.log(json))‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
dtod
Community Contributor

Thanks. It didn't seem to be working, but in fact the issue is that the GUI isn't updating enrollment_state in the course I'm looking at (clicking Restore appears to work, but does not).

dtod
Community Contributor

But, the implication is that there are concluded enrollments (per the GUI), but not per the API.

robotcars
Community Champion

Trying to replicate...[on beta]

I cannot see restore option from the People page.

Going to the course/x/users/x page, and clicking Restore Enrollment... appears to work...

and confirmed the student is now enrolled on the Course People page

the API is now giving me count(1) for completed enrollments, where I had (2)...

Is your course cross listed, maybe it's a :section_id and not a :course_id?

dtod
Community Contributor

I'm seeing the same problem behavior in the same course in our beta instance. There's only one section and it's not cross-listed.

jsavage2
Community Contributor

Hi David,

You need to send the “state[]” parameter. Per https://canvas.instructure.com/doc/api/enrollments.html#method.enrollments_api.index, by default only active and invites enrollments are returned. To find concluded enrollments you’ll need to look for “completed” state, although if you’re like most institutions, some of what you’re looking for may have been deleted or set to inactive.

api/v1/courses/[ID]/enrollments?state[]=completed should give you everyone that shows as “concluded” in the GUI

api/v1/courses/[ID]/enrollments?state[]=completed&state[]=inactive&state[]=deleted should show everyone who was enrolled at some point, but isn’t any longer.

--j

jsavage2
Community Contributor

Hi David,

Is the *course* concluded, or part of a term that's concluded? I don't think you can restore users to a closed course. You may need to override the term dates for the course.

dtod
Community Contributor

Good ideas, but no, the course is not concluded and there are no dates on the term, course or section.

dtod
Community Contributor

Per support it seems like it was some kind of course enrollment caching bug.