Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/GustavoNightmare/InformacionMuseo/llms.txt

Use this file to discover all available pages before exploring further.

BioScan Museo records two distinct activity streams: raw scan events (every time a visitor scans or views a species) and species audit log entries (every admin action such as creating, editing, or deleting a species). Both streams are exposed as filterable JSON endpoints for dashboards, exports, and automated reporting. Both endpoints share their logic with the corresponding HTML admin pages, so any filter accepted by the UI is equally valid here. All requests must be made by an authenticated session whose user account has is_admin = True. Unauthenticated requests are redirected to the login page (HTTP 302); authenticated non-admin requests abort with HTTP 403.

GET /api/admin/metricas

Returns aggregated scan metrics for the given date range and optional filters. The response is built by build_scan_metrics_context(), which runs a set of SQL aggregation queries against the ScanEvent table. Authentication: Login required + is_admin = True. Returns 403 for authenticated non-admin users.

Query parameters

start
string
Start date of the reporting window in YYYY-MM-DD format. Defaults to 30 days before today. If start is later than end, the two values are silently swapped.
end
string
End date (inclusive) in YYYY-MM-DD format. Defaults to today (UTC). Invalid date strings fall back to the default 30-day window.
species_id
string
Filter results to a single species by its internal ID. Ignored if the species does not exist in the database.
origin
string
Filter by scan origin. Accepted values: qr, web, manual. Any other value (including empty) is ignored and treated as “all origins”.

Response

filters
object
The resolved filter values applied to this request.
summary
object
Top-level aggregate metrics for the filtered window.
ranking
array
Per-species scan breakdown, ordered by total_scans descending. Each item contains:
FieldTypeDescription
species_idstringInternal species ID.
qr_idstringQR identifier slug.
nombre_comunstringCommon name.
nombre_cientificostringScientific name.
total_scansintegerTotal scans for this species in the window.
unique_usersintegerDistinct authenticated users who scanned it.
last_scanstringTimestamp of the most recent scan, formatted as YYYY-MM-DD HH:MM. Empty string if unavailable.
chart_data
object
Pre-formatted data arrays for rendering charts.

Example

curl -s \
  -H "Cookie: session=<admin-session-cookie>" \
  "https://your-museum.example.com/api/admin/metricas?start=2024-11-01&end=2024-11-30&origin=qr"
{
  "filters": {
    "start": "2024-11-01",
    "end": "2024-11-30",
    "species_id": "",
    "origin": "qr",
    "species_options": [
      { "id": "condor-001", "qr_id": "condor-001", "nombre_comun": "Cóndor Andino", "nombre_cientifico": "Vultur gryphus" }
    ]
  },
  "summary": {
    "total_scans": 412,
    "unique_users": 87,
    "scanned_species_count": 14,
    "most_scanned_species": {
      "id": "condor-001",
      "qr_id": "condor-001",
      "nombre_comun": "Cóndor Andino",
      "nombre_cientifico": "Vultur gryphus",
      "total_scans": 58
    }
  },
  "ranking": [
    {
      "species_id": "condor-001",
      "qr_id": "condor-001",
      "nombre_comun": "Cóndor Andino",
      "nombre_cientifico": "Vultur gryphus",
      "total_scans": 58,
      "unique_users": 41,
      "last_scan": "2024-11-30 17:23"
    }
  ],
  "chart_data": {
    "daily": {
      "dates": ["2024-11-01", "2024-11-02"],
      "counts": [18, 22]
    },
    "origin": {
      "labels": ["QR", "Web", "Manual"],
      "counts": [412, 0, 0]
    }
  }
}

GET /api/admin/especies/auditoria

Returns a paginated, filterable list of species audit log entries from the SpeciesAuditLog table. Audit events are created automatically whenever a species is created, updated, deleted, or viewed by an admin. Snapshots of the species name, scientific name, and qr_id are stored at write time so that log entries remain informative even after a species is deleted. Authentication: Login required + is_admin = True. Returns 403 for authenticated non-admin users.

Query parameters

species_id
string
Filter by species internal ID. Accepted even if the species has been deleted, as long as historical log entries reference it.
action
string
Filter by action type. Accepted values: created, updated, deleted, viewed_admin. Any other value is ignored.
user_id
string
Filter by the integer user ID of the admin who performed the action. Ignored if the user does not exist.
start
string
Start date in YYYY-MM-DD format. Defaults to 30 days before today.
end
string
End date (inclusive) in YYYY-MM-DD format. Defaults to today (UTC).
page
integer
Page number for pagination. Defaults to 1. Each page contains 10 items.

Response

filters
object
Resolved filter values.
logs
array
Paginated list of audit log entries. Each item contains:
FieldTypeDescription
idintegerAudit log row ID.
species_idstringInternal species ID at the time of the event.
species_namestringCommon name from the species record, or from the snapshot if the species was deleted.
species_scientific_namestringScientific name (same fallback logic).
qr_idstringQR identifier (same fallback logic).
actionstringOne of created, updated, deleted, viewed_admin.
field_namestring | nullThe specific field that changed. Populated for updated events; null for others.
old_valuestring | nullPrevious field value. Populated for updated events.
new_valuestring | nullNew field value. Populated for updated events.
created_atstringEvent timestamp formatted as YYYY-MM-DD HH:MM:SS.
user_idinteger | nullID of the admin who triggered the event. null for system-generated events.
user_namestringDisplay name of the user, or "Sistema" if user_id is null.
notesstring | nullFree-text note attached to the event (e.g., "Especie creada", "Especie eliminada").
total
integer
Total number of log entries matching the filters across all pages.
pagination
object
Pagination metadata.

Example

curl -s \
  -H "Cookie: session=<admin-session-cookie>" \
  "https://your-museum.example.com/api/admin/especies/auditoria?action=updated&page=1&start=2024-11-01&end=2024-11-30"
{
  "filters": {
    "species_id": "",
    "action": "updated",
    "user_id": "",
    "start": "2024-11-01",
    "end": "2024-11-30",
    "species_options": [{ "id": "condor-001", "nombre_comun": "Cóndor Andino" }],
    "user_options": [{ "id": 1, "nombre": "Administrador" }]
  },
  "logs": [
    {
      "id": 47,
      "species_id": "condor-001",
      "species_name": "Cóndor Andino",
      "species_scientific_name": "Vultur gryphus",
      "qr_id": "condor-001",
      "action": "updated",
      "field_name": "descripcion",
      "old_value": "Ave carroñera.",
      "new_value": "Ave carroñera emblemática de los Andes colombianos.",
      "created_at": "2024-11-12 10:45:03",
      "user_id": 1,
      "user_name": "Administrador",
      "notes": null
    }
  ],
  "total": 1,
  "pagination": {
    "page": 1,
    "pages": 1,
    "has_next": false,
    "has_prev": false,
    "next_num": null,
    "prev_num": null
  }
}

Build docs developers (and LLMs) love