Skip to content

Collecting episodes through the API

An external system can read episodes through GET /watcher/client-api/v3/episodes and save them in its own storage. The request returns only episodes accessible to the user. Viewing episodes requires the corresponding camera archive permissions.

The collector queries Watcher with the specified filters and saves returned episodes. The example below exports a fixed interval once; continuous collection requirements follow it.

Prepare access

  1. Choose a user with archive access to the required cameras.
  2. Obtain their access_token or personal API key using the authentication instructions.
  3. Prepare the Watcher address, technical camera name and interval boundaries in Unix milliseconds. Use the same values in both examples below.

Read episodes

curl --fail-with-body --get \
  --header 'Authorization: Bearer <token>' \
  --data-urlencode 'media=entrance-example' \
  --data-urlencode 'opened_at_gte=1793692800000' \
  --data-urlencode 'opened_at_lte=1793779200000' \
  --data-urlencode 'limit=100' \
  'https://watcher.example.com/watcher/client-api/v3/episodes'

Replace media with the camera name. Times are Unix milliseconds. The response contains episodes and pagination cursors. Pass next as cursor until traversal finishes.

Save the result as JSON Lines

This example exports the interval to episodes.jsonl. It requires Python 3 and no additional packages. Save the code as collect_episodes.py, replacing base, media and interval boundaries with your values:

import json
import os
from urllib.parse import urlencode
from urllib.request import Request, urlopen

base = "https://watcher.example.com/watcher/client-api/v3"
params = {
    "media": "entrance-example",
    "opened_at_gte": 1793692800000,
    "opened_at_lte": 1793779200000,
    "limit": 100,
}
headers = {"Authorization": "Bearer " + os.environ["WATCHER_TOKEN"]}

with open("episodes.jsonl", "w", encoding="utf-8") as output:
    while True:
        req = Request(base + "/episodes?" + urlencode(params), headers=headers)
        with urlopen(req, timeout=30) as response:
            result = json.load(response)
        for episode in result.get("episodes", []):
            output.write(json.dumps(episode, ensure_ascii=False) + "\n")
        cursor = result.get("next")
        if not cursor:
            break
        params["cursor"] = cursor

Set the token in the environment and run the file:

read -rs WATCHER_TOKEN
export WATCHER_TOKEN
python3 collect_episodes.py
unset WATCHER_TOKEN

After read, paste the token and press Enter: input is hidden. Successful completion produces episodes.jsonl, with one episode JSON object per line. Check camera names and record times against the selected interval; open one of these episodes in Watcher to verify.

  • Empty file after a successful request — no episodes accessible to the user were returned for the interval. Check camera, time and user permissions.
  • HTTP 401 or 403 — check the token, session state and archive permissions for the camera. Retry after fixing access.
  • Connection error or timeout — check the address and Watcher reachability from the collector's network. Export again after restoring connectivity; a file left by an interrupted run can be incomplete.

For continuous collection, persist state outside the process and update records by episode_id: an episode may be received again with changed data. The integration defines the query interval and processing order. A single export does not guarantee delivery of all subsequent episode changes.