UniFi Protect API — camera management.
List, view, update cameras, capture snapshots, and control PTZ.
Camera fields
id,modelKey,name,macstate—"CONNECTED","CONNECTING", or"DISCONNECTED"isMicEnabled,micVolumeosdSettings,ledSettings,lcdMessageactivePatrolSlot,videoMode,hdrTypefeatureFlags,smartDetectSettings
Updatable fields
name,osdSettings,ledSettings,lcdMessagemicVolume,videoMode,hdrType,smartDetectSettings
Summary
Functions
Gets a specific camera by ID.
Lists all cameras.
Moves the camera to a PTZ preset slot.
Starts a PTZ patrol on the given slot.
Stops the current PTZ patrol.
Takes a camera snapshot. Returns JPEG binary data.
Updates camera settings.
Functions
@spec get(Req.Request.t(), String.t()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Gets a specific camera by ID.
Examples
{:ok, camera} = UnifiApi.Protect.Cameras.get(client, camera_id)
camera["name"] # => "Front Door"
camera["state"] # => "CONNECTED"
@spec list( Req.Request.t(), keyword() ) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Lists all cameras.
Options
:raw— whentrue, return the raw response body binary (skips JSON decoding). Useful when streaming large camera lists or feeding the body to a custom decoder.
Examples
{:ok, cameras} = UnifiApi.Protect.Cameras.list(client)
{:ok, raw_binary} = UnifiApi.Protect.Cameras.list(client, raw: true)
@spec ptz_goto(Req.Request.t(), String.t(), integer()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Moves the camera to a PTZ preset slot.
Examples
{:ok, _} = UnifiApi.Protect.Cameras.ptz_goto(client, camera_id, 1)
@spec ptz_patrol_start(Req.Request.t(), String.t(), integer()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Starts a PTZ patrol on the given slot.
Examples
{:ok, _} = UnifiApi.Protect.Cameras.ptz_patrol_start(client, camera_id, 0)
@spec ptz_patrol_stop(Req.Request.t(), String.t()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Stops the current PTZ patrol.
Examples
{:ok, _} = UnifiApi.Protect.Cameras.ptz_patrol_stop(client, camera_id)
@spec snapshot(Req.Request.t(), String.t(), keyword()) :: {:ok, binary()} | {:error, UnifiApi.Error.t()}
Takes a camera snapshot. Returns JPEG binary data.
Options
:high_quality— request a high-quality snapshot (boolean)
Examples
# Standard quality
{:ok, jpeg} = UnifiApi.Protect.Cameras.snapshot(client, camera_id)
File.write!("snapshot.jpg", jpeg)
# High quality
{:ok, jpeg} = UnifiApi.Protect.Cameras.snapshot(client, camera_id, high_quality: true)
@spec update(Req.Request.t(), String.t(), map()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Updates camera settings.
Examples
{:ok, _} = UnifiApi.Protect.Cameras.update(client, camera_id, %{
name: "Front Door",
micVolume: 80,
videoMode: "highFps",
ledSettings: %{isEnabled: false}
})