API

TMDB Import

Admin API-driven TMDB import that populates the Supabase movies table

POST /api/admin/tmdb-import downloads TMDB's daily export and writes it into the Supabase movies table. The same endpoint is intended for local manual runs and production GitHub Actions schedules.

The import is network and database intensive. Run manual imports only when needed.

How It Works

  1. Builds a URL for yesterday's TMDB export (movie_ids_MM_DD_YYYY.json.gz)
  2. Downloads the gzipped NDJSON export and decompresses it in the import runner
  3. Parses each line as JSON and skips lines that are empty, invalid JSON, or do not match the expected TMDB export shape
  4. Filters out rows where adult: true or popularity < 0.25
  5. Collects valid rows into batches of 1000
  6. Upserts each batch into movies on tmdb_id
  7. Only search-relevant fields are populated during import: tmdb_id, original_title, and popularity
  8. Detailed metadata is filled later by GET /api/movies/:id

Scheduling

Production scheduling is handled in GitHub Actions by sending authenticated POST requests to /api/admin/tmdb-import.

Result

Manual calls and GitHub Actions-triggered calls return the same object:

{
  "imported": 312847,
  "skipped": 14,
  "adultExcluded": 4201,
  "lowPopularityExcluded": 188932,
  "durationSeconds": "47.83"
}
FieldDescription
importedNumber of valid rows queued for Supabase upsert
skippedRows skipped because they were empty, invalid JSON, or failed shape validation
adultExcludedRows dropped because adult: true
lowPopularityExcludedRows dropped because popularity < 0.25
durationSecondsWall-clock time for the full run, as a string with two decimal places

Manual Trigger

POST /api/admin/tmdb-import

Runs the import on demand and returns the result object above. GitHub Actions should call this same endpoint for scheduled imports.

Headers

HeaderDescription
x-admin-tokenMust match ADMIN_API_TOKEN in the server environment

This endpoint does not accept a request body.

Error Codes

  • 400 request body was provided
  • 401 missing or incorrect x-admin-token
  • 409 another import is already running
  • 429 too many failed admin-token attempts from the same IP
  • 502 import failed because the TMDB export stream or Supabase write failed
  • 503 ADMIN_API_TOKEN is not configured

Environment Variables

VariableDescription
NUXT_PUBLIC_SUPABASE_URLSupabase project URL
NUXT_SUPABASE_SERVICE_ROLE_KEYRequired for server-side import writes
ADMIN_API_TOKENGuards the manual trigger endpoint
Copyright © 2026