--- title: API Reference tags: - backend - api - endpoints aliases: - Endpoints - REST API --- # API Reference All endpoints are prefixed with `/api/v1`. See [[Backend]] for server setup. > [!note] The `/killer` endpoint is mounted at the root (outside `/api/v1`). `/auth/*` and `/media/*` paths bypass JWT auth. --- ## Auth > [!info] File: `routes/auth.routes.js` → `controllers/authController.js` | Method | Path | Description | |---|---|---| | `POST` | `/auth/login` | Login with password → returns `{ token, expiresIn }` | | `GET` | `/auth/verify` | Verify JWT token (Bearer auth header) → `{ valid: boolean }` | --- ## Watch Buddies > [!info] File: `routes/watch-buddy.routes.js` → `controllers/watchBuddyController.js` | Method | Path | Description | |---|---|---| | `GET` | `/watch-buddies/search?q=` | Search watch buddies by name | | `GET` | `/watch-buddies/:id` | Get watch buddy by ID | | `POST` | `/watch-buddies` | Create watch buddy | | `PUT` | `/watch-buddies/:id` | Update watch buddy | | `DELETE` | `/watch-buddies/:id` | Delete watch buddy | --- ## Entries > [!info] File: `routes/entry.routes.js` → `controllers/entryController.js` | Method | Path | Description | |---|---|---| | `GET` | `/entries` | Get all library entries (with IDs, ratings, genres, networks, media, seens, seasons) | | `GET` | `/entries/:id` | Get entry by ID — triggers [[Services#Lazy Refresh\|lazy refresh]] if stale | | `POST` | `/entries` | Add entry from TMDB: `{ tmdb_id, is_tvserie }` | | `PUT` | `/entries/:id` | Update entry fields: `{ entryData }` | | `PUT` | `/entries/:id/ratings` | Update ratings: `{ entryRatings }` | | `PUT` | `/entries/:id/ids` | Update external IDs | | `DELETE` | `/entries/:id` | Delete entry and all related data | | `GET` | `/entries/:id/seasons` | Get all seasons for a TV entry | | `GET` | `/entries/:id/credits` | Get ALL credits (cast + crew) for an entry, with associated `person` populated. Used by [[Pages#EntryCastsPage\|EntryCastsPage]] | | `GET` | `/entries/:id/recommendations` | Live TMDB recommendations for a library entry (not stored) | | `GET` | `/entries/:id/artwork` | TMDB posters/backdrops/logos merged with the entry's media — see [[Artwork]] | | `POST` | `/entries/:id/artwork` | Download a TMDB image into the media table: `{ type, file_path }` | | `PUT` | `/entries/:id/refresh` | Force refresh from TMDB (details, ids, ratings, genres, networks, seasons, episodes, credits) | | `PUT` | `/entries/:id/fetch-collection` | Fetch/create TMDB collection for entry | | `GET` | `/entries/sync-series` | Batch refresh all non-ended TV series | | `POST` | `/entries/:id/media` | Upload media (multipart — poster/backdrop/logo) | | `PUT` | `/entries/:entryId/media/:mediaId` | Set media as selected | | `DELETE` | `/entries/:entryId/media/:mediaId` | Delete entry media (auto-selects next available media of same type if deleted media was selected) | ### TMDB Proxy | Method | Path | Description | |---|---|---| | `GET` | `/entries/tmdb/trending/:type` | Trending movies/tv | | `GET` | `/entries/tmdb/popular/:type` | Popular movies/tv | | `GET` | `/entries/tmdb/top-rated/:type` | Top-rated movies/tv | | `GET` | `/entries/tmdb/upcoming/movie` | Upcoming movies | | `GET` | `/entries/tmdb/search?query=&page=` | Multi-search | | `GET` | `/entries/tmdb/preview/:type/:tmdbId` | Preview a TMDB entry before adding. Includes `entry` (same shape as a library entry), `seasons` and `credits` (cast + directors) | | `GET` | `/entries/tmdb/recommendations/:type/:tmdbId` | Recommendations by TMDB id (entries not in the library) | | `GET` | `/entries/tmdb/artwork/:type/:tmdbId` | TMDB artwork by TMDB id (read-only) | --- ## Collections > [!info] File: `routes/collection.routes.js` → `controllers/collectionController.js` | Method | Path | Description | |---|---|---| | `GET` | `/collections` | All collections | | `GET` | `/collections/:id` | Collection by ID with entries | | `POST` | `/collections` | Create user collection | | `PUT` | `/collections/:id` | Update (multipart — poster/backdrop) | | `PUT` | `/collections/:id/refresh` | Refresh from TMDB | | `PUT` | `/collections/:id/parts` | Fetch missing parts from TMDB | | `DELETE` | `/collections/:id` | Delete collection | | `POST` | `/collections/:collectionId/entries/:entryId` | Add entry to collection | | `PATCH` | `/collections/:collectionId/entries/:entryId` | Update entry order | | `DELETE` | `/collections/:collectionId/entries/:entryId` | Remove entry from collection | | `POST` | `/collections/collection-with-entry` | Create collection + add first entry | --- ## Entry Seen (Movie Watch Records) > [!info] File: `routes/entry-seen.routes.js` → `controllers/entrySeenController.js` See [[Watch Tracking]] for the accuracy system. | Method | Path | Description | |---|---|---| | `GET` | `/entry-seen` | All entry seens | | `GET` | `/entry-seen/by-entry/:entryId` | Watch records for an entry (includes `buddies` association) | | `GET` | `/entry-seen/:id` | Single record by ID | | `POST` | `/entry-seen` | Create: `{ entry_id, date_seen, seen_with, accuracy, buddy_ids? }` — `buddy_ids` links watch buddies | | `PUT` | `/entry-seen/:id` | Update record — accepts `{ date_seen, seen_with, buddy_ids? }` | | `DELETE` | `/entry-seen/:id` | Delete record | --- ## Episode Seen (Episode Watch Records) > [!info] File: `routes/episode-seen.routes.js` → `controllers/episodeSeenController.js` | Method | Path | Description | |---|---|---| | `GET` | `/episode-seen` | All episode seens | | `GET` | `/episode-seen/by-episode/:episodeId` | Watch records for an episode (includes `buddies` association) | | `GET` | `/episode-seen/by-entry/:entryId` | All episode seens for an entry (includes `buddies` + episode/season info) | | `GET` | `/episode-seen/:id` | Single record by ID | | `POST` | `/episode-seen` | Create: `{ entry_id, episode_id, date_seen, seen_with, accuracy, buddy_ids? }` | | `PUT` | `/episode-seen/:id` | Update record — accepts `{ date_seen, seen_with, episode_id?, buddy_ids? }` | | `DELETE` | `/episode-seen/:id` | Delete record | --- ## Seasons > [!info] File: `routes/season.routes.js` → `controllers/seasonController.js` | Method | Path | Description | |---|---|---| | `GET` | `/seasons` | All seasons | | `GET` | `/seasons/:id` | Season by ID (includes episodes with episodeSeens) | | `GET` | `/seasons/:id/episodes` | Season episodes only | | `POST` | `/seasons` | Create season | | `PUT` | `/seasons/:id` | Update season | | `DELETE` | `/seasons/:id` | Delete season | --- ## Episodes > [!info] File: `routes/episode.routes.js` → `controllers/episodeController.js` | Method | Path | Description | |---|---|---| | `GET` | `/episodes/month/:startDate/:endDate` | Episodes airing between dates (for [[Calendar]]) | --- ## Media > [!info] File: `routes/media.routes.js` → `controllers/mediaController.js` See [[Media System]] for details. | Method | Path | Description | |---|---|---| | `GET` | `/media` | All custom media records | | `GET` | `/media/:category/:type/:size/:fileName` | Serve media file | **URL pattern:** `/media/{entries|collections|seasons|episodes|peoples|watch-buddies}/{posters|backdrops|logos|stills|profiles}/{preview|full}/{filename}` --- ## Discovery Videos > [!info] File: `routes/video.routes.js` → `controllers/videoController.js` See [[Discovery Videos]] for details. | Method | Path | Description | |---|---|---| | `GET` | `/discovery-videos?page=&limit=` | Paginated list (includes linked entries) | | `POST` | `/discovery-videos` | Multipart upload: `videos[]` (≤ 10), `description`, `entryIds` (JSON array) | | `PUT` | `/discovery-videos/:id` | Update title / description / entry links | | `DELETE` | `/discovery-videos/:id` | Delete record + files from disk | | `GET` | `/discovery-videos/:id/thumbnail` | Thumbnail image — generated on demand when missing | | `GET` | `/discovery-videos/:id/stream` | Video stream with HTTP Range support (`?token=` auth) | --- ## People > [!info] File: `routes/people.routes.js` → `controllers/peopleController.js` See [[People]] for the lazy-fetch pattern. | Method | Path | Description | |---|---|---| | `GET` | `/people` | All people | | `GET` | `/people/popular?limit=` | Popular people (local DB) | | `GET` | `/people/search?query=` | Search people (local DB) | | `GET` | `/people/:id` | Person by ID (lazy-fetch from TMDB if needed) | | `GET` | `/people/:id/credits` | Person's credits | | `GET` | `/people/:id/tmdb-filmography` | Full TMDB filmography | | `POST` | `/people` | Create person | | `POST` | `/people/fetch` | Fetch by TMDB ID: `{ tmdb_id }` | | `PUT` | `/people/:id` | Update person | | `PUT` | `/people/:id/refresh` | Refresh from TMDB | | `DELETE` | `/people/:id` | Delete person | | `POST` | `/people/:id/media` | Upload profile picture | | `GET` | `/people/tmdb/popular` | TMDB popular people | | `GET` | `/people/tmdb/search?query=` | TMDB people search | | `GET` | `/people/tmdb/preview/:tmdbId` | Preview TMDB person before adding — returns local + TMDB data with filmography | --- ## Statistics > [!info] File: `routes/statistics.routes.js` → `controllers/statisticsController.js` See [[Statistics]] for chart details. | Method | Path | Description | |---|---|---| | `GET` | `/statistics/watch-time` | All-time watch time (series + movies, in minutes) | | `GET` | `/statistics/watch-time/year/:year` | Yearly watch time by month | | `GET` | `/statistics/watch-count/year/:year` | Yearly watch count by month | | `GET` | `/statistics/watch-weekday` | Watch-day distribution (EXACT accuracy only) | --- ## History > [!info] File: `routes/history.routes.js` → `services/historyService.js` See [[History]]. | Method | Path | Description | |---|---|---| | `GET` | `/history/years` | Years with watches, newest first: `[{ year, movies, episodes }]` | | `GET` | `/history/:year` | Every movie/episode watch in a year, newest first: `{ year, entries: { [id]: entry }, events: [...] }` | --- ## Settings > [!info] File: `routes/settings.routes.js` → `controllers/settingsController.js` | Method | Path | Description | |---|---|---| | `GET` | `/settings` | Get all settings | | `PUT` | `/settings` | Update settings | --- ## Maintenance > [!info] File: `routes/maintenance.routes.js` → `controllers/maintenanceController.js` See [[Settings Page#Cleanup]] for the UI. ### Orphan Files & Media Records | Method | Path | Description | |---|---|---| | `GET` | `/maintenance/orphan-files` | Dry scan — files on disk without DB records | | `DELETE` | `/maintenance/orphan-files` | Delete orphan files | | `GET` | `/maintenance/orphan-media-records` | Dry scan — DB records without files on disk | | `DELETE` | `/maintenance/orphan-media-records` | Delete orphan DB records | **Response:** `{ posters: number, logos: number, backdrops: number, stills: number }` ### Orphan People | Method | Path | Description | |---|---|---| | `GET` | `/maintenance/orphan-people` | Dry scan — people without any credits | | `DELETE` | `/maintenance/orphan-people` | Delete orphan people | **Response:** `{ count: number }` ### Missing Directors | Method | Path | Description | |---|---|---| | `GET` | `/maintenance/missing-directors` | Scan for entries missing director credits | | `POST` | `/maintenance/missing-directors` | Fix — fetch missing directors from TMDB | **Response:** `{ count: number, fixed: number }` ### Duplicate Credits | Method | Path | Description | |---|---|---| | `GET` | `/maintenance/duplicate-credits` | Scan for duplicate (person, entry, role) credits | | `DELETE` | `/maintenance/duplicate-credits` | Clean duplicate credits (keeps one per group) | **Response:** `{ groups: number, duplicates: number, deleted: number }` ### Watch Status Auto-Fix | Method | Path | Description | |---|---|---| | `POST` | `/maintenance/auto-fix-watch-statuses` | Auto-correct entry watch statuses based on watched episodes (e.g., mark series as completed/watching/plan-to-watch) | **Response:** `{ completed: number, watching: number, planToWatch: number }` ### Impossible Seen Dates | Method | Path | Description | |---|---|---| | `GET` | `/maintenance/impossible-seen-dates` | Scan for movies watched before their release date | | `POST` | `/maintenance/impossible-seen-dates` | Fix — add to "Movies with impossible seen date" collection | **Response:** Scan → `{ count: number }`, Fix → `{ count: number, added: number }` --- ### Stale Entries Refresh | Method | Path | Description | |---|---|---| | `GET` | `/maintenance/stale-entries?hours=24` | Count of entries not refreshed in the last `hours` + current job status | | `POST` | `/maintenance/stale-entries/refresh?hours=24` | Start refreshing them in the background (`202`; `409` if already running) | | `DELETE` | `/maintenance/stale-entries/refresh` | Cancel the running job | Entries with auto sync off are skipped. TMDB requests go through the [[TMDB Integration#Rate Limiting|rate limiter]]. --- ## Import > [!info] File: `routes/import.routes.js` → `controllers/importController.js` See [[Import System]] for details. | Method | Path | Description | |---|---|---| | `POST` | `/import/movies` | Bulk import movies | | `POST` | `/import/tmdb` | Bulk import by TMDB IDs | | `POST` | `/import/episodes-watch-history` | Bulk import episode watch history | --- ## Utility | Method | Path | Description | |---|---|---| | `GET` | `/ping` | Health check → `{ message: 'pong' }` | | `GET` | `/killer` | Debug: crash backend (outside `/api/v1`) | | `POST` | `/killer` | Debug: crash backend (outside `/api/v1`) |