API Documentation


General

Permission Levels

LevelDescription
PublicNo authentication required
Any authenticated userValid Bearer token required
AdminUser with admin flag set to true
SuperadminUser with superadmin flag set to true

Common Response Status Codes

StatusMeaning
200OK — successful GET, PATCH, PUT
201Created — successful POST
204No Content — successful DELETE
401Unauthorized — missing or invalid token
403Forbidden — insufficient permissions
404Not Found — resource does not exist
422Unprocessable Entity — validation errors

Authentication

All API endpoints require authentication via a Bearer token (JWT) issued by PiratenSSO (Keycloak), unless marked as public.

Obtaining a token

Apps acting on behalf of a member (e.g. the iOS app) sign the user in with the OAuth 2.0 Authorization Code flow with PKCE against the PiratenSSO realm Piratenlogin and send the user's access token. The server identifies the user by the token's sub claim and creates the user record on first request.

Server-to-server clients can use the client credentials flow. The resulting token belongs to the client's service account, not to a member:

POST https://sso.piratenpartei.de/realms/Piratenlogin/protocol/openid-connect/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
&client_id=YOUR_CLIENT_ID
&client_secret=YOUR_CLIENT_SECRET

The response contains an access_token:

{
  "access_token": "eyJhbGciOiJSUzI1NiIs...",
  "expires_in": 300,
  "token_type": "Bearer"
}

Using the token

Include the token in the Authorization header of every request:

Authorization: Bearer eyJhbGciOiJSUzI1NiIs...

Authentication errors

StatusBodyCause
401{"error": "Authorization header required"}No Authorization header sent
401{"error": "Invalid token: ..."}Token is expired, malformed, or signed by an untrusted issuer

Example: authenticated request

curl -H "Authorization: Bearer eyJhbG..." \
     -H "Accept: application/json" \
     https://meine-piraten.de/tasks.json

Tasks

A task represents an actionable item assigned to an organizational entity and category.

Endpoints

MethodPathDescriptionPermission
GET/tasks.jsonList all tasksAny authenticated user
GET/tasks/:id.jsonGet a single taskAny authenticated user
POST/tasks.jsonCreate a taskAdmin
PATCH/PUT/tasks/:id.jsonUpdate a taskAny authenticated user (see field restrictions below)
DELETE/tasks/:id.jsonDelete a taskAdmin

Request parameters (create / update)

Wrap parameters in a task key:

{
  "task": {
    "title":               "string (required for create, max 200 characters)",
    "description":         "string (optional, max 2000 characters)",
    "completed":           "boolean",
    "creator_name":        "string",
    "time_needed_in_hours": "integer (optional)",
    "activity_points":     "integer (optional)",
    "due_date":            "date (YYYY-MM-DD, optional)",
    "urgent":              "boolean (optional)",
    "category_id":         "integer (required for create, foreign key)",
    "entity_id":           "integer (required for create, foreign key)",
    "status":              "string (optional, see status transitions below)",
    "assignee":            "string (optional, PiratenSSO username)"
  }
}

Field update restrictions for non-admin users

Non-admin users may only update status and assignee. Any other fields they send are silently ignored: the request still returns 200 OK with the unchanged values. Check the response body instead of assuming the change was applied.

Status transitions

Task status follows a strict state machine.

FromAllowed transitionsWho can transition
openclaimedAny authenticated user
claimedcompleted, openAny authenticated user
completeddone, claimedAdmin only
done(none — terminal state)—

Response example (single task)

{
  "id": 1,
  "title": "Wahlkampfmaterial bestellen",
  "description": "Flyer und Plakate für den Wahlkampf bestellen",
  "completed": false,
  "creator_name": "pirat42",
  "time_needed_in_hours": 2,
  "due_date": "2025-06-01",
  "urgent": true,
  "activity_points": 10,
  "category_id": 1,
  "entity_id": 1,
  "status": "open",
  "assignee": null,
  "created_at": "2025-05-04T12:00:00.000Z",
  "updated_at": "2025-05-04T12:00:00.000Z",
  "url": "https://meine-piraten.de/tasks/1.json"
}

Comments

Comments are nested under tasks. Each comment belongs to a task and is ordered by creation date (ascending).

Endpoints

MethodPathDescriptionPermission
GET/tasks/:task_id/comments.jsonList comments for a taskAny authenticated user
POST/tasks/:task_id/comments.jsonCreate a commentAny authenticated user
DELETE/tasks/:task_id/comments/:id.jsonDelete a commentAdmin

Request parameters (create)

Wrap parameters in a comment key:

{
  "comment": {
    "author_name": "string",
    "text":        "string (required)"
  }
}

Response example (single comment)

{
  "id": 1,
  "task_id": 1,
  "author_name": "pirat42",
  "text": "Flyer sind bestellt.",
  "created_at": "2025-05-04T12:30:00.000Z",
  "updated_at": "2025-05-04T12:30:00.000Z",
  "url": "https://meine-piraten.de/tasks/1/comments/1.json"
}

Entities

Entities represent organizational units (Landes-, Bezirks-, or Kreisverbände). Entities can be self-referentially nested (e.g. a KV belonging to an LV).

Endpoints

MethodPathDescriptionPermission
GET/entities.jsonList all entitiesAny authenticated user
GET/entities/:id.jsonGet a single entityAny authenticated user
POST/entities.jsonCreate an entityAdmin
PATCH/PUT/entities/:id.jsonUpdate an entityAdmin
DELETE/entities/:id.jsonDelete an entityAdmin

Request parameters (create / update)

Wrap parameters in an entity key:

{
  "entity": {
    "name":         "string (not validated server-side; send a non-empty name)",
    "entity_level": "string (optional, one of: LV, BZV, KV)",
    "parent_entity_id": "integer (optional, parent entity foreign key)"
  }
}

Entity levels

ValueMeaning
LVLandesverband
BZVBezirksverband
KVKreisverband

Response example (single entity)

{
  "id": 1,
  "name": "Piratenpartei Bayern",
  "entity_level": "LV",
  "parent_entity_id": null,
  "created_at": "2025-01-01T00:00:00.000Z",
  "updated_at": "2025-01-01T00:00:00.000Z",
  "parent_entity_name": null,
  "url": "https://meine-piraten.de/entities/1.json"
}

Categories

Categories are used to classify tasks.

Endpoints

MethodPathDescriptionPermission
GET/categories.jsonList all categoriesAny authenticated user
GET/categories/:id.jsonGet a single categoryAny authenticated user
POST/categories.jsonCreate a categoryAdmin
PATCH/PUT/categories/:id.jsonUpdate a categoryAdmin
DELETE/categories/:id.jsonDelete a categoryAdmin

Request parameters (create / update)

Wrap parameters in a category key:

{
  "category": {
    "name": "string (not validated server-side; send a non-empty name)"
  }
}

Response example (single category)

{
  "id": 1,
  "name": "Öffentlichkeitsarbeit",
  "created_at": "2025-01-01T00:00:00.000Z",
  "updated_at": "2025-01-01T00:00:00.000Z",
  "url": "https://meine-piraten.de/categories/1.json"
}

News

News posts are sourced from Telegram channel updates. This endpoint is public and does not require authentication.

Endpoints

MethodPathDescriptionPermission
GET/api/news.jsonList recent news postsPublic (no authentication required)

Query parameters

ParameterTypeDefaultDescription
limitinteger50Number of posts to return (max 200)

Example request

curl -H "Accept: application/json" \
     https://meine-piraten.de/api/news.json?limit=10

Response example (list)

[
  {
    "chat_id": -1001234567890,
    "message_id": 42,
    "posted_at": "2026-03-01T14:30:00Z",
    "text": "Neuer Blogpost: Unsere Positionen zur Digitalpolitik..."
  },
  {
    "chat_id": -1001234567890,
    "message_id": 41,
    "posted_at": "2026-02-28T10:00:00Z",
    "text": "Einladung zum nächsten Stammtisch..."
  }
]

Posts are ordered by posted_at descending (newest first) and limited to posts from the last 30 days.


Admin Requests

Any authenticated user can request admin privileges. Requests are reviewed by superadmins. Approving a request automatically grants the user admin rights.

Endpoints

MethodPathDescriptionPermission
GET/admin_requests/status.jsonCheck your own admin statusAny authenticated user
POST/admin_requests.jsonSubmit an admin requestAny authenticated user
PATCH/admin_requests/:id/approve.jsonApprove a requestSuperadmin
PATCH/admin_requests/:id/reject.jsonReject a requestSuperadmin
PATCH/admin_requests/:id/demote.jsonRevoke admin rights from a userSuperadmin

Check admin status

GET /admin_requests/status.json
Authorization: Bearer eyJhbG...

Returns:

{ "admin": false, "pending_request": true }

pending_request is true while you have a request awaiting review. Hide the request form in that case.

Submit a request

Send the reason as a top-level parameter:

POST /admin_requests.json
Authorization: Bearer eyJhbG...
Content-Type: application/json

{
  "reason": "Ich möchte Aufgaben für meinen KV verwalten."
}

Success response (201 Created)

{
  "id": 1,
  "status": "pending",
  "reason": "Ich möchte Aufgaben für meinen KV verwalten.",
  "created_at": "2026-02-17T10:00:00.000Z"
}

Validation error (422 Unprocessable Entity)

{
  "errors": ["Reason can't be blank"]
}

Only one pending request per user is allowed. A second submission returns 422 with "Es liegt bereits eine offene Anfrage vor." A new request is possible once the previous one was approved or rejected.

Approve / Reject / Demote (superadmin only)

PATCH /admin_requests/1/approve.json
Authorization: Bearer eyJhbG...

Grants admin rights to the request's user. Returns:

{ "status": "approved" }
PATCH /admin_requests/1/reject.json
Authorization: Bearer eyJhbG...

Rejects the request without changing user permissions. Returns:

{ "status": "rejected" }
PATCH /admin_requests/1/demote.json
Authorization: Bearer eyJhbG...

Revokes admin rights from the request's user and marks the request as rejected. Returns:

{ "status": "rejected" }

Non-superadmin users receive 403 Forbidden for approve / reject / demote endpoints.


Messages

Private messages between users of this server. Request bodies are top-level JSON (no wrapper key). Send Accept: application/json or append .json.

Endpoints

MethodPathDescriptionPermission
GET/api/messages.jsonYour 50 most recent received messages, newest firstAny authenticated user
POST/api/messages.jsonSend a messageAny authenticated user
PATCH/PUT/api/messages/:id.jsonMark a received message as readRecipient only

Response example (list)

[
  {
    "id": 1,
    "sender_id": 42,
    "body": "Kannst du die Flyer bis Freitag fertig haben?",
    "read": false,
    "created_at": "2026-03-19T10:30:00Z"
  }
]

Send a message

POST /api/messages.json
Content-Type: application/json

{ "recipient_id": 42, "body": "Ja, kein Problem!" }

Returns 201 Created with { "id": 2 }. A blank body or unknown recipient_id returns 422 with { "errors": [...] }.

Mark as read

PATCH /api/messages/:id.json returns 200 OK with {}. A message that does not exist or was not sent to you returns 404 with { "error": "Not found" }.


Push Subscriptions

Register APNs device tokens for server-sent push notifications. Request bodies are top-level JSON.

Endpoints

MethodPathDescriptionPermission
POST/api/push_subscriptions.jsonRegister a token or update its preferences (upsert by token)Any authenticated user
DELETE/api/push_subscriptions/:token.jsonRemove a token (idempotent, always 200)Any authenticated user

Register / update

POST /api/push_subscriptions.json
Content-Type: application/json

{
  "token": "a1b2c3d4e5f6...",
  "platform": "ios",
  "messages": true,
  "todos": false,
  "forum": false,
  "news": true
}

platform defaults to "ios". Each category is enabled only if sent as the JSON boolean true; missing values or the string "true" disable it. Every call overwrites all four preferences and assigns the token to the calling user. Returns 200 OK with {}, or 422 with { "errors": [...] }.

Notification payloads

Payloads contain no personal data: alert title is always "PIRATEN App", the body a fixed German text. badge is the recipient's number of unread messages.

TriggerCategoryAlert bodyExtra keysRecipients
New messagemessagesDu hast eine neue NachrichtdeepLink: "message", topicId (message id)The recipient
Task created, or its status / assignee changedtodosEin ToDo wurde aktualisiertdeepLink: "todo", todoIdThe assignee, or all todos subscribers if the task has no assignee
New Telegram news postnewsEs gibt neue NeuigkeitendeepLink: "forum"All news subscribers

The forum category can be stored but nothing on the server sends forum notifications.