This article will provide some guidance on the procedure to poll whether teachers have taken class attendance.
The process detailed below is described in a way that is common for any list endpoints in many kinds of public APIs. These list endpoints such as "Get all Classes" can be used to find the IDs of the respective resources that are required for specialized API call. Other list endpoints in ManageBac are "Get all students", "Get all Parents", "Get all Teachers", and "Get all Memberships".
Step 1: Use the list endpoint to loop through all classes
Our first step is to obtain the class IDs in order to make subsequent calls to the attendance endpoints. There are two list endpoints that provides this information, "Get all Memberships" and "Get all Classes".
The "Get all Classes" endpoint `/classes` is the most straight-fowards approach to obtaining class IDs. This endpoint by default responds with active classes, which are not archived. However, if you wanted, you can also retrieve the archived classes by passing the `archived=1` as a query parameter.
/classes?page=1&archived=0
/classes?page=2&archived=0
...
In each respective loop, the "Get all Classes" endpoint will respond with an object that holds a collection of classes, in the `classes` property, as well as metadata about the collection represented in the response.
{
"classes": [ ... ],
"meta": {
"current_page": 1,
"total_pages": 3,
"total_count": 122,
"per_page": 50,
}
}
Above is an example of the response. The `classes` property is a list of classes (details not shown) and `meta` is a property that describes the information in `classes`.
The `meta` key can be used to build the next request, as list endpoints do not return all of the resources in one call. You need to use pagination to obtain all of the resources available at the list endpoint. The meta property in the response indicates how many classes were returned, and whether or not there are more pages. If there are no more pages, then `current_page` will equal `total_pages`. Furthermore, if there are only 10 pages available, but page 11 is requested, the `classes` property in the response will be an empty list.
The ID for each class can be obtained by looping through the `classes` property:
{
"classes": [
{
"id": 1234567,
"uniq_id": "2022-Science-1",
"start_term_id": 45678901,
"end_term_id": 90121345,
...
}, {
"id": 1234568,
"uniq_id": 2022-English-1",
"start_term_id": 45678901,
"end_term_id": 45679123,
...
}
]
}
Above, you see that each resource provides some IDs. Please note that `uniq_id` is the same value that is present in the classes profile, and is for the school to populate. That ID has no effect on ManageBac systems, and is provided for the school to identify a class with unique identifier unique to the school.
The other IDs, however, are internal database IDs, and can be used to retrieve further information about a resource.
Step 3: Loop through the Get Class Attendance for a Date endpoint
With those class IDs, use the Get Class Attendance for a Date endpoint; you would be able to download the information that has been input into ManageBac. The response provides the lesson periods in which attendance was taken. If no attendance was taken for that day, it is an empty object.
The information can be stored in a database or csv as required.
GET https://api.managebac.com/classes/{{class_id}}/attendance/date/YYYY-MM-DD
If the teacher has not taken attendance the response will be empty:
{
"students": [
{
"id": 14350656,
"attendance": {}
},
{
"id": 14350661,
"attendance": {}
},
{
"id": 14350650,
"attendance": {}
},
{
"id": 14350651,
"attendance": {}
},
{
"students": [
{
"id": 14350656,
"attendance": {
"4": {
"status": "Present",
"note": ""
}
}
},
{
"id": 14350661,
"attendance": {
"4": {
"status": "Present",
"note": ""
}
}
},
There is a "Get a Class Timetable" endpoint which will output the attendance settings for the given class by ID. Since a class can be associated across academic years, the information is nested as an array:
{
"timetable": {
"academic_years": [{
"id": 123,
"name": "August 2022 – July 2023",
"start_date": "2022-08-01",
"end_date": "2023-07-31",
"period_starts_count_from": 0,
"slots": [{
"day": 2,
"period": 1,
"location": "",
"enabled": true
}, {
"day": 5,
"period": 2,
"location": "",
"enabled": true
}, {
"day": 7,
"period": 3,
"location": "",
"enabled": true
}]
}]
}
}
- This only works for "today." If you were to use the "Get Attendance for a Date" for yesterday, none of the attendance will be empty objects, even if the teacher has not taken attendance. It will instead show as the same as the default "Present." If this is an issue, you may want to explore the idea of changing your default "Present" to "Not Taken" and force teachers to use a custom category to indicate Present.
- The class timetable is output in terms of rotation days. In other words, if it is Day 2 but the class meets on Day 1 and Day 3, there needs to be some mapping to know up-front what day it is, and which classes meet on that day. This can be achieved by exporting the timetable and keeping this information stored and looked up.
- Additionally, some classes may only meet in the first term, but still be active (not archived) in ManageBac. In this circumstance, the "Get all Memberships" endpoint may be the better approach to use as the list endpoint, since it has a useful filter that can automatically exclude classes that do not meet "today". By using the `classes` query parameter to "active" and sending today's date for `class_happens_on`, it will filter out archived classes and also filter out any class who, according to the term associations, does not meet today: