API & Services¶
local_suap exposes a custom HTTP API (without using Moodle core web services) to receive data from SUAP and return information consumed by the AVA Panel and other integrations. All services pass through a single entry point.
Entry Point and Authentication¶
api/index.php handles requests at /local/suap/api/?<service_name>:
disables Moodle cookies/CSRF (
NO_MOODLE_COOKIES) — the API is stateless and token-authenticated;validates the service name against a whitelist and includes the corresponding file;
instantiates
\local_suap\<service_name>_serviceand calls->call();any uncaught exception is formatted into a JSON response
{"error": {"message", "code", "source", "trace"}}with HTTP status matching the exception code (or 500).
The base service class (api/servicelib.php) implements token authentication:
function authenticate() {
// Requires Authentication (or authentication) header: "Token <auth_token>"
// 400 if header missing; 401 if token invalid
}
function call() {
$this->authenticate();
echo json_encode($this->do_call());
}
Each concrete service overrides do_call(). The base implementation throws 501 Not Implemented.
Available Services¶
Whitelist of services enabled in api/index.php:
Service |
HTTP Method |
Purpose |
|---|---|---|
|
GET/POST |
Returns plugin and Moodle version without side effects. |
|
GET |
Lists logbooks, coordination rooms, and practicals for a user. |
|
GET |
Returns unread messages/notifications count for a user (used by AVA Panel). |
|
GET |
Toggles favorite state of a course for a user. |
|
GET |
Changes visibility of a course if user has |
|
GET |
Saves an arbitrary user preference ( |
|
POST |
Primary service: receives course structure/enrolments and syncs categories, courses, users, cohorts, enrolments, and groups. See SUAP → Moodle Synchronization. |
|
GET |
Fetches grades (categories in |
get_diarios¶
Classifies courses assigned to a user based on the shortname pattern:
|
Classification |
|---|---|
|
Coordination ( |
|
Practical ( |
|
Logbook ( |
Other cases |
Treated as logbook without structural regex filter. |
Accepts query parameters: username, semestre, situacao, ordenacao, disciplina, curso, arquetipo, q, page, page_size.
sync_down_grades¶
HTTP Call Example:
GET /local/suap/api/sync_down_grades.php?diario_id=20231.1.15806.1E.TEC.1386 HTTP/1.1
Returns student enrolment ID, full name, grades object, and activity completion percentage for students in the specified logbook.
Sample Payload — sync_up_enrolments¶
Minimal POST payload:
POST /local/suap/api/?sync_up_enrolments HTTP/1.1
Authentication: Token changeme
{
"curso": {"id": 1, "nome": "Technology in Computer Networks", "codigo": "00001", "descricao": "..."},
"turma": {"id": 2, "codigo": "20221.6.00001.3E"},
"campus": {"id": 1, "sigla": "EAD", "descricao": "Campus EaD"},
"diario": {"id": 2, "sigla": "TEC.0001", "situacao": "Aberto", "descricao": "Database Systems", "descricao_historico": "Database Systems"},
"componente": {"id": 1, "tipo": 1, "sigla": "TEC.0001", "periodo": null, "optativo": false, "descricao": "Database Systems", "qtd_avaliacoes": 2, "descricao_historico": "Database Systems"}
}