Create a Session Token
Exchange your organization Developer Key (Melody Key) for a short-lived session token used to control devices.
Send your Developer Key as Authorization: Bearer <melody_key>. Optionally restrict the
token to specific devices by listing their Device Keys; omit device_keys to allow every
device linked to your organization.
The returned token is then used on every /device/* request as
Authorization: Bearer <session_token> together with the X-Device-Key header.
Flow
- Obtain your Organization ID and Developer Key from Melody (see Authentication).
- Link a device to your organization via
POST /device/otp/confirm/v2to get its Device Key. - Call this endpoint with your Developer Key to receive a session token.
- Control the device via
/device/*using the session token andX-Device-Key.
Usage
# 1. Create a session token
curl -X POST https://api.getmelody.io/api/sessions/v2 \\
-H "Authorization: Bearer <melody_key>" \\
-H "Content-Type: application/json" \\
-d '{"device_keys": ["alpha-bravo-charlie-delta"]}'
# -> { "token": "eyJhbGciOi...", "expires_in": 900 }
# 2. Control the device with the session token
curl https://api.getmelody.io/device/status \\
-H "Authorization: Bearer <session_token>" \\
-H "X-Device-Key: alpha-bravo-charlie-delta"
Authorizations
Developer Key (Melody Key) tied to your organization. Your Organization ID and Developer Key are issued to you by Melody — contact support@getmelody.io to request them. Used to create session tokens via POST /api/sessions/v2, and to link devices via the X-Org-Key header on POST /device/otp/confirm/v2.
Body
Device Keys the session token may control. Omit to allow every device linked to your organization.
^[a-z]+-[a-z]+-[a-z]+-[a-z]+$Response
Session token created
Response from POST /api/sessions/v2. Contains a short-lived session token used with the X-Device-Key header.