In order to get all the enrollments for all the courses, we need to generate an API token first. Please refer to this article on how to do that:
Getting Started Using the API with an Example in C#
This example makes use of a third party package called Rest Sharp in order to simplify the process. For simplicity, all calls return plain text but it's possible to parse the json response into a defined model using Rest Sharp.
Once we get the token, we can use combination of two methods (GetCourses and GetEnrollments) to get all the enrollments for all the courses shown as below.
public void GetCourses(string token) { var client = new RestClient($"http://{PortalName}.myabsorb.com/api/Rest/v1/"); var request = new RestRequest("Courses?externalId={CourseExternalId}", Method.GET); request.AddHeader("Authorization", token); var response = client.Execute(request); var content = response.Content; Console.WriteLine(content); var jsonobject = JsonConvert.DeserializeObject<IList<Courses>>(content); foreach (Courses model in jsonobject) { Console.WriteLine("Getting Enrollments for Course : " + model.Id); GetEnrollments(model.Id, token); } } public void GetEnrollments(Guid courseId, string token) { var client = new RestClient($"http://{PortalName}.myabsorb.com/api/Rest/v1/"); var request = new RestRequest($"courses/{courseId}/enrollments?status={EnrollmentStatus}", Method.GET); request.AddHeader("Authorization", token); var response = client.Execute(request); var content = response.Content; Console.WriteLine(content); } public class Courses { public Guid Id { get; set; } }
Please Note: That GetCourses will pull all the courses in the portal, however they can also be filtered by modified date and external id. GetEnrollments would take each course and list all the enrollments for that course. This can then further be filtered by Modified Date and Status.
For performance reasons , we usually recommend pulling all the data only when necessary and to include filters whenever possible.