@ErickCarreno
If you want a list of users, rather than enrollments, you can use the List users in a course endpoint.
When you look at the parameters, you see enrollment_state[] that allows you to filter by enrollment state. By default, only "active" and "invited" are returned. You would most likely need to use "completed", although your institution may use "inactive" as well. Since it's an array with the [] at the end, you can use multiple enrollment_state[] parameters.
The list enrollments endpoint allows for similar functionality, except it's state[] rather than enrollment_state[] and you have more options. Enrollments take longer than users to generate.
In both cases, you can filter by the user's role so you just get students rather than instructors, TAs, and other people who have access.
You can also use GraphQL to get the information, which is probably faster when fetching the data, but has a steeper learning curve before you can get the information and the information is harder to process once you get it.