Ladok3 automated access

While I still do not have access to the Ladok3 API, it is possible to establish a session to the Ladok3 GUI and then make requests as if you were a web client. In the rest of the text, I will use Ladok to refer to Ladok3.

This lead to several programs:

canvas_ladok3_spreadsheet.py canvas_course_id -- Use the data in a Canvas course room together with the data from Ladok to create a spreadsheet of students in the course and include their Canvas user_id, name, Ladok3 Uid, program_code, program name, etc.

Note that the course_id can be given as a numeric value or a string which will be matched against the courses in the user's dashboard cards. It will first match against course codes, then short name, then original names.

ladok3_course_instance_to_spreadsheet.py course_code course_instance -- Use the data in Ladok together with the data from Canvas to create a spreadsheet of students in a course instance and include their Canvas user_id (or "not in Canvas" if they do not have a Canvas user_id), name, Ladok3 Uid, program_code, program name, etc.

cl_user_info.py Canvas_user_id|KTHID|Ladok_id [course_id] -- Use the data in a Canvas course room together with the data from Ladok to find information about a user - such as their "personnumber", integration ID, program and specialization.

Finally, using only the Canvas API - find students that lack an integration_id

canvas_students_missing_integration_ids.py canvas_course_id -- Use the data in a Canvas course room to create a spreadsheet of students in the course who are missing an integration ID.

Background - various IDs that are used in Canvas

Canvas has a number of different IDs that are important to understand. The student information system (SIS) IDs are lightly document at https://canvas.instructure.com/doc/api/file.object_ids.html Links to an external site.

In addition to the user's Canvas ID (user_id), we will also consider the following

  • sis_user_id
  • sis_login_id
  • sis_integration_id

The Canvas user_id is simply a number that was assigned when the user was added to the Canvas instance. For example, my user_id is 29.

The sis_user_id at KTH is the user's KTHID. For example, my sis_user_id is u1d13i2c. These IDs are assigned uniquely to users and do not change, even if a user changes their name or "personnumber".

The sis_login_id is the user's login name. For example, my sis_login_id is maguire@kth.se.

The sis_integration_id at KTH is the user's ID in Ladok (ladok_id) . It can be recognized using the regular expression: '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}', i.e., xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  where "x" is a hexadecimal digit. The result is that the sis_integration_id uniquely identifies a student within Ladok. By using it as a sis_integration_id there is a unique mapping between a Canvas user and their corresponding identity in Ladok.

Many of the GET requests can be given a ladok_id and thus you can retrieve information about that student.

Background - Canvas course_id

Each course in Canvas has a course_id, this is simply a number assigned when the Canvas course is created.  At KTH this course_id refers to something that is called a "Canvas course room", i.e., the place within the KTH Canvas instance where the material for a course is.

Background "course instances"

An important concept is that of a course instance (kurstillfälle), some times referred to as a course round. This is a very important concept because at KTH each course has a course code (such as II2202), but in any given year there can be several course instances - both to handle the course being offered at different times during an academic year and to deal with administrative issues such as course instances that are only for students in a specified set of programs. A course instance identifier is a number, such as 51127 and 51491 (two different instances of the course II2202). This course instance identifier is called a tillfälleskod in Ladok. The English translation used by Ladok for this identifier is "Session code".

Inside Ladok, there are entries for each course code and for each of its course instances. For a given course code and a given course instance, there is a set of students associated (these are the "participants" in the course instance (deltagare på aktivitetstillfälle)).

Code

Internally within KTH the code can be found at https://gits-15.sys.kth.se/maguire/ladok3. The initial code for the ladok3.py library was written by someone else (as noted in the source code and as forked from this person's repository).