🔌 HTTP REST API & Webhook Reference (/api/v1/*)

DuckyDeck Studio (v0.1.25 for Windows 10/11 & Linux) includes an embedded, low-latency HTTP/1.1 REST API server (src/api_server.rs) that exposes full programmatic control over your duckyPad Pro, profiles, keys, DuckyScript 3 compiler, Persistent Global Variables (_GV0.._GV31), live RGB LEDs, and microSD card sync.

Machine-Readable Specifications: openapi.yaml  •  openapi.json  •  swagger.json  •  REST_API.md

🔐 Authentication, Persistence & Security

Enable the server in ☰ → Settings → HTTP REST API Server (default listen address: 127.0.0.1:28491, disabled by default). Pass your 160-bit token (ddk_...) via either header:

Authorization: Bearer ddk_0123456789abcdef0123456789abcdef01234567
# or
X-API-Token: ddk_0123456789abcdef0123456789abcdef01234567

Credential Storage: Stored in the OS secret store (KDE Wallet / libsecret on Linux; Windows Credential Manager on Windows 10/11) with fallback to ~/.config/duckydeck-studio/kwin_rules.json (Linux) or %APPDATA%\duckydeck-studio\kwin_rules.json (Windows).

Defense-in-Depth Guards: Token comparison uses constant-time byte matching (paths::constant_time_str_eq()). Untrusted Host headers and cross-origin browser requests are rejected with 403 Forbidden (no wildcard Access-Control-Allow-Origin: *), and slot/PGV/SD/ESP32-HA mutations plus App Launch JSON payloads unconditionally enforce authentication.

📋 Complete Endpoint Summary (/api/v1/*)

Method & Path Description
GET /api/v1/healthUnauthenticated liveness probe ({"ok":true,"service":"duckydeck-studio","version":"0.1.25"}).
GET /api/v1/openapi.json | /swagger.json | /openapi.yamlUnauthenticated OpenAPI 3.0.3 / Swagger specification.
GET /api/v1/statusFull device connection, firmware (v1.1.2), active profile, SD sync, and auto-switcher state.
GET /api/v1/devices | POST /api/v1/devices/select | /renameList discovered duckyPads, select active device, or assign a custom friendly name ({"serial":"...","customName":"Left Pad"}).
GET /api/v1/profilesList all profiles and their properties.
POST /api/v1/profilesCreate a new profile ({"name":"Streaming"}) or duplicate an existing profile ({"name":"Copy","duplicateFrom":1}).
POST /api/v1/profiles/selectSelect active profile and switch hardware ({"profile":2,"switchHardware":true}).
POST /api/v1/profiles/reorderMove profile ({"fromProfile":3,"toProfile":1}) and update Auto-Switcher rules.
GET /api/v1/profiles/{num}Get full profile details, webhook config, and all 26 slots.
PUT | PATCH /api/v1/profiles/{num}Update profile properties (name, bgColor, oledRotation, widgetRotation, webhook).
DELETE /api/v1/profiles/{num}Delete profile {num} (Fallback Profile is protected).
GET /api/v1/profiles/{num}/slots/{slot}Get configuration and scripts for slot 1..26.
PUT | POST | PATCH /api/v1/profiles/{num}/slots/{slot}Program a slot's labels, icons, RGB color, DuckyScript 3 code, or host action.
POST /api/v1/profiles/{num}/slots/{slot}/triggerRemotely execute the slot's configured host action (@HOST_APP, @HA_ACTION, @WEBHOOK).
POST /api/v1/dsvm/compileValidate and compile DuckyScript 3 source into .dsb bytecode + IEEE CRC32.
GET | PUT | POST /api/v1/pgvRead or write Persistent Global Variables (_GV0.._GV31).
POST /api/v1/ledsLive-override per-key RGB LEDs or restore profile colors ({"restore":true}).
POST /api/v1/sd/sync | /reload | /mount | /unmountSync .dsb bytecode & profiles to microSD, reload, mount, or safely unmount.
POST /api/v1/device/sleep | /wake | /reboot | /sync-rtcSleep, wake, soft-reboot, or synchronize hardware RTC clock.
GET /api/v1/logsRetrieve recent system, HID, script, and automation event logs.

💻 Quick curl Examples

export DDK_TOKEN="ddk_your_token_here"
export DDK_URL="http://127.0.0.1:28491/api/v1"

# 1. Switch active profile on hardware to Profile 2
curl -s -X POST "$DDK_URL/profiles/select" \
  -H "Authorization: Bearer $DDK_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"profile": 2, "switchHardware": true}'

# 2. Program Profile 1, Key 1 with an OLED icon, label, color, and DuckyScript 3 macro
curl -s -X PUT "$DDK_URL/profiles/1/slots/1" \
  -H "Authorization: Bearer $DDK_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "labelLine1": "🌐",
    "labelLine2": "WEB",
    "colorHex": "#00A8FF",
    "scriptContent": "CTRL t\nDELAY 100\nSTRINGLN https://duckydeckstudio.com"
  }'

# 3. Live-override Key 1..3 RGB LEDs
curl -s -X POST "$DDK_URL/leds" \
  -H "Authorization: Bearer $DDK_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"leds": [{"slot": 1, "colorHex": "#10b981"}, {"slot": 2, "colorHex": "#38bdf8"}]}'

🔔 Outbound Profile Change Webhooks

Configure per-profile webhooks in Profile Properties or a global webhook in Settings to notify Home Assistant, Node-RED, or custom servers whenever the active profile changes (supports template variables {{profile_number}}, {{profile_name}}, {{previous_profile_number}}, {{source}}, {{device_serial}}, and {{timestamp}}).