Skip to content

Authentication

The PrintStudio API uses two authentication mechanisms: session cookies for the web dashboard and API keys for programmatic access.

All API requests from external clients must include the X-API-Key header:

Terminal window
curl http://localhost:8787/api/orders \
-H "X-API-Key: psk_live_abc123..."

Go to Dashboard → Settings → API Keys → New Key. Set a name, expiry, and role (see below). The full key is shown once — copy it immediately.

Terminal window
# Requires an existing admin session or API key
curl -X POST http://localhost:8787/api/auth/api-keys \
-H "Content-Type: application/json" \
-H "X-API-Key: your-admin-key" \
-d '{
"name": "Production integration",
"role": "operator",
"expiresAt": "2025-12-31T00:00:00Z"
}'

Response:

{
"id": "key-uuid",
"name": "Production integration",
"key": "psk_live_abc123...",
"role": "operator",
"createdAt": "2024-01-15T10:00:00Z",
"expiresAt": "2025-12-31T00:00:00Z"
}
RolePermissions
customerRead own orders, create orders, view SKU catalog
operatorFull order/job management, printer control, inventory
adminEverything + user management, API key management, system config

Endpoints that require elevated roles return 403 Forbidden if your key’s role is insufficient.

The web dashboard uses server-side sessions backed by Web Crypto SHA-256. Sessions are stored in a cookie (printstudio_session) with HttpOnly, SameSite=Strict, and Secure (in production).

Terminal window
# Login (returns Set-Cookie header)
curl -X POST http://localhost:8787/api/auth/login \
-H "Content-Type: application/json" \
-d '{ "email": "operator@example.com", "password": "..." }' \
-c cookies.txt
# Use session cookie for subsequent requests
curl http://localhost:8787/api/dashboard \
-b cookies.txt
Terminal window
curl -X DELETE http://localhost:8787/api/auth/api-keys/{keyId} \
-H "X-API-Key: your-admin-key"

Revoked keys return 401 Unauthorized immediately.

API keys are prefixed to help distinguish environments and accidentally-committed secrets:

PrefixEnvironment
psk_live_Production
psk_test_Development / test
Terminal window
SESSION_SECRET=a-long-random-string-min-32-chars
API_KEY_SALT=another-random-string

Both are required. Generate with:

Terminal window
openssl rand -base64 32