Skip to content

REST API Reference

waliori edited this page Aug 5, 2025 · 1 revision

REST API Reference

Complete API documentation for the Smart Sit-Stand Desk Controller. All endpoints support CORS for cross-origin requests.

🌐 Base URL

http://<pico-ip-address>/

Replace <pico-ip-address> with your Pico W's IP address on your network.

πŸ“‹ Available Endpoints

Status & Information

Get Current Height

GET /get_height

Description: Returns the current desk height in real-world units.

Response:

{"height": "95.5"}

Get Min/Max Heights

GET /get_minmax

Description: Returns the configured minimum and maximum height limits.

Response:

{"min": 72.0, "max": 120.0}

Get Preset Heights

GET /get_presets

Description: Returns all configured preset heights.

Response:

["1: 95.5", "2: 110.0", "3: 115.2"]

Check Lock Status

GET /islocked

Description: Returns whether the desk is currently locked.

Response:

{"locked": false}

Movement Controls

Move Up

GET /forward

Description: Starts moving the desk upward.

Response:

{"status": "ok"}

Note: Returns {"status": "nok"} if desk is locked.

Move Down

GET /backward

Description: Starts moving the desk downward.

Response:

{"status": "ok"}

Note: Returns {"status": "nok"} if desk is locked.

Stop Movement

GET /stop

Description: Immediately stops any desk movement.

Response:

{"status": "ok"}

Position Control

Go to Specific Height

GET /go?height=100.5

Parameters:

  • height (required): Target height in real-world units (float)

Description: Moves desk to the specified height.

Response:

{"status": "ok"}

Go to Preset

GET /go_preset?preset=1

Parameters:

  • preset (required): Preset number (1, 2, or 3)

Description: Moves desk to the specified preset position.

Response:

{"status": "ok"}

Note: Returns {"status": "nok"} if preset doesn't exist.

Security Controls

Lock Desk

GET /lock

Description: Locks the desk to prevent all movement.

Response:

{"status": "ok"}

Unlock Desk

GET /unlock

Description: Unlocks the desk to allow movement.

Response:

{"status": "ok"}

Configuration

Set Minimum Height

GET /set_min?min=70.0

Parameters:

  • min (required): New minimum height limit (float)

Description: Updates the minimum height limit.

Response:

{"status": "ok"}

Set Maximum Height

GET /set_max?max=125.0

Parameters:

  • max (required): New maximum height limit (float)

Description: Updates the maximum height limit.

Response:

{"status": "ok"}

πŸ”§ Response Format

All API endpoints return JSON responses with consistent formatting.

Success Response

{
  "status": "ok",
  "data": "response_data"
}

Error Response

{
  "status": "nok",
  "error": "Description of error"
}

HTTP Headers

All responses include CORS headers:

Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: *

πŸ“± Integration Examples

JavaScript/Fetch API

// Get current height
const response = await fetch('http://192.168.1.100/get_height');
const data = await response.json();
console.log('Current height:', data.height);

// Move to specific height
await fetch('http://192.168.1.100/go?height=110.0');

// Go to preset 1
await fetch('http://192.168.1.100/go_preset?preset=1');

Python Requests

import requests

# Get current height
response = requests.get('http://192.168.1.100/get_height')
height = response.json()['height']
print(f'Current height: {height}')

# Move desk up
requests.get('http://192.168.1.100/forward')

# Stop movement after delay
time.sleep(2)
requests.get('http://192.168.1.100/stop')

cURL Commands

# Get current height
curl http://192.168.1.100/get_height

# Move to sitting height
curl "http://192.168.1.100/go?height=95.0"

# Lock desk
curl http://192.168.1.100/lock

# Check if locked
curl http://192.168.1.100/islocked

πŸ”’ Security Considerations

Physical Lock

The /lock endpoint provides a software lock that prevents all movement commands. When locked:

  • Movement endpoints (/forward, /backward, /go, /go_preset) return {"status": "nok"}
  • Configuration changes are still allowed
  • The lock persists across system restarts

Network Security

  • API is accessible to all devices on the local network
  • No authentication required (designed for home/office use)
  • Consider network-level security (VPN, firewall rules) for enhanced protection

⚠️ Important Notes

Safety

  • Always verify desk response before issuing multiple commands
  • Use /stop endpoint for emergency stops
  • Physical buttons override API commands
  • Height limits are enforced in software

Rate Limiting

  • No built-in rate limiting
  • Avoid rapid successive calls to prevent system overload
  • Allow movement commands to complete before issuing new ones

Error Handling

  • Always check response status ("ok" vs "nok")
  • Handle network timeouts gracefully
  • Implement retry logic for critical operations

πŸ“ž Support: For API issues or feature requests, use GitHub Issues