Authentication
Before you can use the API, you need to log in with your admin account. The login endpoint returns a session token that you include in all subsequent requests.
Log in
curl -s -X POST http://your-server/api/login \
-H "Content-Type: application/json" \
-d '{"user": "admin@fablab.org", "pass": "your-password"}'
The server responds with a token:
{"token": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"}
For convenience, you can store the token in a shell variable:
TOKEN=$(curl -s -X POST http://your-server/api/login \
-H "Content-Type: application/json" \
-d '{"user": "admin@fablab.org", "pass": "your-password"}' | jq -r '.token')
Providing the token
Include the token in every request. The server accepts it in three places (checked in this order):
- Authorization header (recommended):
Authorization: Bearer $TOKEN - Session cookie (set automatically after login if you preserve cookies)
- Query parameter (fallback):
?token=$TOKEN
Already logged in
If the session cookie already contains a valid token, a second login request returns the existing token without creating a new session.
Log out
When you are done, invalidate the session:
curl -X POST http://your-server/api/logout \
-H "Authorization: Bearer $TOKEN"
Response:
{"success": true}
Error responses
| Situation | Status | Message |
|---|---|---|
Missing user or pass |
400 | Missing credentials |
| Unknown user | 401 | User not found |
| Wrong password | 401 | Incorrect password |
| Account not allowed | 403 | Permission denied |
| Expired or invalid token (on other endpoints) | 403 | Invalid token. Please log in and try again. |
Note:
Session tokens expire when the server-side session times out. If you receive a403 error on any endpoint, simply log in again to get a fresh token.
API tokens
For automated or long-running integrations you can create API tokens instead of using session-based login. API tokens are managed through the admin UI and can be used directly as bearer tokens — no login step required.
Creating an API token
- Open the Admin panel in the 2log UI.
- Navigate to the API Tokens section.
- Provide a name, an optional description, permissions, and an optional expiration date.
- Click Create. The token string is shown once — copy and store it securely.
Using an API token
Use the token exactly like a session token. The server accepts it in the same three places:
# Authorization header (recommended)
curl http://your-server/api/some-endpoint \
-H "Authorization: Bearer <API_TOKEN>"
# Query parameter
curl "http://your-server/api/some-endpoint?token=<API_TOKEN>"
Key differences from session tokens
| Session token | API token | |
|---|---|---|
| Created via | POST /api/login |
Admin UI |
| Lifetime | Expires on session timeout | Valid until expiration date (or indefinitely if none is set) |
| Scope | Full admin access | Configurable permissions |
| Revocation | POST /api/logout |
Delete in Admin UI |