{
 "openapi": "3.1.0",
 "info": {
  "title": "iSpis custom server",
  "version": "1.6.0",
  "description": "Endpoints your custom server answers. iSpis calls them; you implement them\n(hosted: `ispis/service.ts` in your repository, see /docs/ispis-yaml).\n\n**Every request** except `/health` carries `Authorization: Bearer <secret>`\n(hosted: the value of env `ISPIS_AUTH`; your own server: `service.auth`)\nplus `X-Ispis-Ak` (tenant code), `X-Ispis-Login` (e-mail of the acting\nuser, the system login for automatic calls) and `X-Ispis-Request` (id for\nyour log). Answer `401` when the bearer does not match.\n\n**Errors**: any 4xx/5xx; put a short ASCII message into the\n`x-ispis-error` response header (shown to the user), optionally JSON\n`{ \"error\": \"...\" }` in the body.\n\n**Hosted runtime** (`ispis/service.ts`): listen on the unix socket\n`ISPIS_SOCKET` (own server: TCP `ISPIS_HOST:ISPIS_PORT`); readable env\n`ISPIS_AK`, `ISPIS_URL`, `ISPIS_SOCKET`, `ISPIS_PORT`, `ISPIS_HOST`,\n`ISPIS_AUTH`, `PG*`, `TZ`, `HOME`, `DENO_DIR` and `ISPIS_SECRET_<id>` of the\nkeys listed in ispis.yaml `secrets`; read only inside the repository,\nwrite to `var/` and `log/`; 512 MB, half a CPU, 30 s per request; exit on\nSIGTERM within 5 s.\n"
 },
 "servers": [
  {
   "url": "unix:$ISPIS_SOCKET",
   "description": "hosted ispis/service.ts"
  },
  {
   "url": "{serviceUrl}",
   "description": "your own server (ispis.yaml service.url)",
   "variables": {
    "serviceUrl": {
     "default": "https://custom.example.com/ispis"
    }
   }
  }
 ],
 "security": [
  {
   "bearer": []
  }
 ],
 "paths": {
  "/health": {
   "get": {
    "summary": "Liveness probe",
    "description": "Called after start (up to 30 s) and by the conformance test. No authorization.",
    "security": [],
    "responses": {
     "200": {
      "description": "The server is ready (any body; `{ \"ok\": true }` recommended)."
     }
    }
   }
  },
  "/action/{id}": {
   "get": {
    "summary": "Custom action (ispis.yaml customActions, type Remote)",
    "description": "Called when a user runs the action. Case/person actions get `refno`;\nrun from the case list on several cases it is called once per case\n(or once with `refnos`). File actions get `peId`.\n",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "refno",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "RefNo of the case (domain case/person/claim/paid/txn)"
     },
     {
      "name": "refnos",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "comma-separated RefNos (batch run from the case list)"
     },
     {
      "name": "peId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "file id (domain file)"
     }
    ],
    "responses": {
     "200": {
      "description": "Result of the action.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ActionResult"
        }
       }
      }
     }
    }
   }
  },
  "/var": {
   "get": {
    "summary": "Template variable (ispis.yaml templateCustomVariables)",
    "description": "`[% Id %]` in a template; an object result is used as `[% Id.Key %]`.",
    "parameters": [
     {
      "name": "name",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "refno",
      "in": "query",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Value of the variable.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/VarResult"
        }
       }
      }
     }
    }
   }
  },
  "/link": {
   "get": {
    "summary": "Link in the case header (hosted only)",
    "parameters": [
     {
      "name": "refno",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "`{ url, title }`, or `{}` / `null` for no link.",
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "$ref": "#/components/schemas/Link"
          },
          {
           "type": "object",
           "maxProperties": 0
          },
          {
           "type": "null"
          }
         ]
        }
       }
      }
     }
    }
   }
  },
  "/section/{id}": {
   "get": {
    "summary": "Section HTML (ispis.yaml sections, hosted only)",
    "description": "HTML fragment shown in the case card (`placement=detail`, `refno` = case)\nor on the overview page (`placement=dashboard`, empty `refno`). Bootstrap 5\nclasses, no `<script>`, no `<style>`; an empty body hides the section.\n",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "refno",
      "in": "query",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "placement",
      "in": "query",
      "required": true,
      "schema": {
       "$ref": "#/components/schemas/Placement"
      }
     },
     {
      "$ref": "#/components/parameters/Rights"
     },
     {
      "$ref": "#/components/parameters/CanEdit"
     }
    ],
    "responses": {
     "200": {
      "description": "HTML fragment (may be empty).",
      "content": {
       "text/html": {
        "schema": {
         "type": "string"
        }
       }
      }
     }
    }
   }
  },
  "/section/{id}/{form}": {
   "post": {
    "summary": "Form submitted from a section",
    "description": "`<form data-api=\"/section/<placement>/<id>/<RefNo>/<form>\">` in your HTML;\nthe fields arrive as a JSON object. After success the section is\nre-rendered, or the browser follows `redirect` (relative iSpis URL).\nA 4xx with `{ error }` is shown inside the form.\n",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "form",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "refno",
      "in": "query",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "placement",
      "in": "query",
      "required": true,
      "schema": {
       "$ref": "#/components/schemas/Placement"
      }
     },
     {
      "$ref": "#/components/parameters/Rights"
     }
    ],
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "additionalProperties": {
         "type": "string"
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Done.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "redirect": {
           "type": "string",
           "pattern": "^/",
           "description": "relative iSpis URL",
           "e.g. /pripad#48": null
          },
          "error": {
           "type": "string"
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/event/{name}": {
   "post": {
    "summary": "Event (ispis.yaml events, hosted only)",
    "description": "Sent for every event you list in `events`, in the background (the user\ndoes not wait for you), about a second after the change, at most once\nand without retry; order is not guaranteed (use `at`). Changes your own\nserver makes do not raise events. Reconcile from the database where it\nmatters (e.g. a schedule that looks at cases changed since its last\nrun). `X-Ispis-Delivery` is a unique id of the delivery.\n",
    "parameters": [
     {
      "name": "name",
      "in": "path",
      "required": true,
      "schema": {
       "$ref": "#/components/schemas/EventName"
      }
     },
     {
      "name": "X-Ispis-Delivery",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "oneOf": [
         {
          "$ref": "#/components/schemas/TaskEvent"
         },
         {
          "$ref": "#/components/schemas/CaseCreatedEvent"
         },
         {
          "$ref": "#/components/schemas/StateChangedEvent"
         },
         {
          "$ref": "#/components/schemas/LabelsChangedEvent"
         },
         {
          "$ref": "#/components/schemas/FileUploadedEvent"
         },
         {
          "$ref": "#/components/schemas/PaymentMatchedEvent"
         },
         {
          "$ref": "#/components/schemas/IsdsReceivedEvent"
         }
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Accepted (any body is ignored)."
     },
     "204": {
      "description": "Accepted."
     }
    }
   }
  },
  "/customRoute/{route}": {
   "get": {
    "summary": "Public route for your own frontend (ispis.yaml customRoutes, hosted only)",
    "description": "`https://<iSpis domain>/customRoute/<account>/<route>` (GET or POST, as\ndeclared) is passed here unchanged with the query string and body; your\nanswer (status, content-type, body) goes back unchanged. No login\n(`auth: none`): identify end users yourself. CORS only for\n`frontend.origins`; at most 60 requests a minute per IP and 600 per\naccount; 2 MB both ways, 30 s. The client's own `Authorization` header\narrives as `X-Ispis-Client-Authorization`.\n",
    "parameters": [
     {
      "name": "route",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "X-Ispis-Origin",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "Origin of the browser request (empty for server calls)"
     },
     {
      "name": "X-Ispis-Client-IP",
      "in": "header",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "X-Ispis-Client-Authorization",
      "in": "header",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Any content."
     }
    }
   },
   "post": {
    "summary": "Public route (POST)",
    "parameters": [
     {
      "name": "route",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "content": {
      "*/*": {
       "schema": {}
      }
     }
    },
    "responses": {
     "200": {
      "description": "Any content."
     }
    }
   }
  },
  "/cron/{id}": {
   "post": {
    "summary": "Scheduled job (ispis.yaml schedules, hosted only)",
    "description": "Called by the cron expression of the schedule (server time Europe/Prague),\none run at a time (a run still in progress skips the next one), up to\n10 minutes. Put your automations and reports here. The status of the\nlast run (code, duration, `x-ispis-error`) is shown in Settings → Custom.\n",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "id",
         "at"
        ],
        "properties": {
         "id": {
          "type": "string"
         },
         "at": {
          "type": "string",
          "format": "date-time",
          "description": "planned time of this run (UTC)"
         },
         "lastRunAt": {
          "type": [
           "string",
           "null"
          ],
          "format": "date-time",
          "description": "time of the previous run (UTC), null for the first one"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Done (any body is ignored)."
     },
     "204": {
      "description": "Done."
     }
    }
   }
  }
 },
 "x-ispis-service-api": {
  "description": "Your hosted server calls iSpis back for changes that need iSpis business\nlogic (audit, follow-up actions, sending): `POST http://ispis/api/service/v1/<method>`\nover the unix socket `ISPIS_API_SOCKET` with `Authorization: Bearer <ISPIS_AUTH>`\nand a JSON body. Answer: JSON (`ok: true` + fields below), or 4xx with\n`{ \"error\" }` and `x-ispis-error`. Changes made this way do not raise\nevents. They are done as the system user of the account and audited as\n`service:<account>`.\n",
  "methods": {
   "case/setState": {
    "body": {
     "refno": "string",
     "state": "string",
     "category": "string?"
    },
    "returns": {
     "refno": "string",
     "category": "string",
     "state": "string"
    }
   },
   "case/addLabel": {
    "body": {
     "refno": "string",
     "label": "string"
    },
    "returns": {
     "labels": "[string]"
    },
    "note": "only labels declared in ispis.yaml labels (when you declare them)"
   },
   "case/removeLabel": {
    "body": {
     "refno": "string",
     "label": "string"
    },
    "returns": {
     "labels": "[string]"
    }
   },
   "case/setField": {
    "body": {
     "refno": "string",
     "key": "string",
     "value": "string | null"
    },
    "returns": {
     "key": "string",
     "value": "string?"
    },
    "note": "re-indexes the case when the key is in additionalFulltext"
   },
   "case/reindex": {
    "body": {
     "refno": "string",
     "refnos": "[string]?"
    },
    "returns": {
     "count": "integer"
    }
   },
   "task/create": {
    "body": {
     "refno": "string",
     "verb": "string",
     "text": "string?",
     "due": "YYYY-MM-DD[ HH:MM]?",
     "assignee": "e-mail?"
    },
    "returns": {
     "peId": "integer"
    }
   },
   "task/complete": {
    "body": {
     "peId": "integer",
     "result": "string?"
    },
    "returns": {
     "peId": "integer"
    }
   },
   "note/add": {
    "body": {
     "refno": "string",
     "text": "string"
    },
    "returns": {
     "peId": "integer"
    }
   },
   "auth/checkLogin": {
    "body": {
     "email": "string",
     "password": "string"
    },
    "returns": {
     "ok": "boolean",
     "email": "string?",
     "role": "string?"
    },
    "note": "checks a login of a user of this account (portal for your own people); 20 attempts an hour per e-mail"
   },
   "email/send": {
    "body": {
     "to": "string",
     "subject": "string",
     "text": "string"
    },
    "returns": {
     "ok": "boolean"
    },
    "note": "plain-text e-mail from iSpis (e.g. a one-time code); limited per account and per address"
   },
   "sms/send": {
    "body": {
     "to": "+420…",
     "text": "string"
    },
    "returns": {
     "ok": "boolean",
     "id": "string?"
    },
    "note": "SMS through the account's / iSpis gateway; limited per account and per number"
   },
   "message/send": {
    "body": {
     "refno": "string",
     "method": "email | isds",
     "personId": "integer",
     "templateId": "integer?",
     "to": "string?",
     "subject": "string?",
     "text": "string?"
    },
    "returns": {
     "draftId": "string",
     "sent": "boolean"
    },
    "note": "a template or a text by e-mail or data box",
    "prepared and sent at once (irreversible)": null
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearer": {
    "type": "http",
    "scheme": "bearer"
   }
  },
  "parameters": {
   "Rights": {
    "name": "X-Ispis-Rights",
    "in": "header",
    "description": "comma-separated rights of the section (`right` + `rights`) the user has",
    "schema": {
     "type": "string"
    }
   },
   "CanEdit": {
    "name": "X-Ispis-Can-Edit",
    "in": "header",
    "description": "`1` when the user has the section `right` (may submit its forms)",
    "schema": {
     "type": "string",
     "enum": [
      "0",
      "1"
     ]
    }
   }
  },
  "schemas": {
   "Placement": {
    "type": "string",
    "enum": [
     "detail",
     "dashboard"
    ]
   },
   "EventName": {
    "type": "string",
    "enum": [
     "taskDone",
     "taskCreated",
     "caseCreated",
     "stateChanged",
     "labelsChanged",
     "fileUploaded",
     "paymentMatched",
     "isdsReceived"
    ]
   },
   "EventBase": {
    "type": "object",
    "required": [
     "refno",
     "login",
     "at"
    ],
    "properties": {
     "refno": {
      "type": "string",
      "description": "RefNo of the case (project.path)"
     },
     "login": {
      "type": "string",
      "description": "e-mail of the acting user (the system login for automatic changes)"
     },
     "at": {
      "type": "string",
      "format": "date-time",
      "description": "when the change happened (UTC)"
     }
    }
   },
   "TaskEvent": {
    "description": "taskDone (a task was finished) / taskCreated (a task was created)",
    "allOf": [
     {
      "$ref": "#/components/schemas/EventBase"
     },
     {
      "type": "object",
      "required": [
       "peId",
       "verb"
      ],
      "properties": {
       "peId": {
        "type": "integer",
        "description": "id of the task (project_entry)"
       },
       "verb": {
        "type": "string",
        "description": "task verb (ispis.yaml taskVerbs)"
       }
      }
     }
    ],
    "example": {
     "refno": "48",
     "peId": 1234,
     "verb": "refund",
     "login": "jana@example.com",
     "at": "2026-11-27T10:15:00Z"
    }
   },
   "CaseCreatedEvent": {
    "description": "caseCreated – a new case (UI, import, API)",
    "allOf": [
     {
      "$ref": "#/components/schemas/EventBase"
     },
     {
      "type": "object",
      "properties": {
       "category": {
        "type": [
         "string",
         "null"
        ]
       },
       "state": {
        "type": [
         "string",
         "null"
        ]
       },
       "batch": {
        "type": [
         "string",
         "null"
        ],
        "description": "group (batch) of the case"
       }
      }
     }
    ],
    "example": {
     "refno": "49",
     "category": "Inkaso",
     "state": "Mimosoud",
     "batch": null,
     "login": "jana@example.com",
     "at": "2026-11-27T10:15:00Z"
    }
   },
   "StateChangedEvent": {
    "description": "stateChanged – category and/or state of the case changed",
    "allOf": [
     {
      "$ref": "#/components/schemas/EventBase"
     },
     {
      "type": "object",
      "required": [
       "from",
       "to"
      ],
      "properties": {
       "from": {
        "$ref": "#/components/schemas/CategoryState"
       },
       "to": {
        "$ref": "#/components/schemas/CategoryState"
       }
      }
     }
    ],
    "example": {
     "refno": "48",
     "from": {
      "category": "Inkaso",
      "state": "Mimosoud"
     },
     "to": {
      "category": "Inkaso",
      "state": "Soud"
     },
     "login": "jana@example.com",
     "at": "2026-11-27T10:15:00Z"
    }
   },
   "CategoryState": {
    "type": "object",
    "properties": {
     "category": {
      "type": [
       "string",
       "null"
      ]
     },
     "state": {
      "type": [
       "string",
       "null"
      ]
     }
    }
   },
   "LabelsChangedEvent": {
    "description": "labelsChanged – labels added and/or removed (not by your server)",
    "allOf": [
     {
      "$ref": "#/components/schemas/EventBase"
     },
     {
      "type": "object",
      "required": [
       "added",
       "removed"
      ],
      "properties": {
       "added": {
        "type": "array",
        "items": {
         "type": "string"
        }
       },
       "removed": {
        "type": "array",
        "items": {
         "type": "string"
        }
       }
      }
     }
    ],
    "example": {
     "refno": "48",
     "added": [
      "BL"
     ],
     "removed": [],
     "login": "jana@example.com",
     "at": "2026-11-27T10:15:00Z"
    }
   },
   "FileUploadedEvent": {
    "description": "fileUploaded – a new file on the case",
    "allOf": [
     {
      "$ref": "#/components/schemas/EventBase"
     },
     {
      "type": "object",
      "required": [
       "peId"
      ],
      "properties": {
       "peId": {
        "type": "integer",
        "description": "id of the file (project_entry)"
       },
       "fileType": {
        "type": [
         "string",
         "null"
        ]
       },
       "name": {
        "type": [
         "string",
         "null"
        ],
        "description": "file name"
       }
      }
     }
    ],
    "example": {
     "refno": "48",
     "peId": 1240,
     "fileType": "statement",
     "name": "vypis.pdf",
     "login": "jana@example.com",
     "at": "2026-11-27T10:15:00Z"
    }
   },
   "PaymentMatchedEvent": {
    "description": "paymentMatched – a payment was assigned to the case (first time)",
    "allOf": [
     {
      "$ref": "#/components/schemas/EventBase"
     },
     {
      "type": "object",
      "required": [
       "paymentId",
       "amountCents"
      ],
      "properties": {
       "paymentId": {
        "type": "integer",
        "description": "id of the payment (paid)"
       },
       "amountCents": {
        "type": "integer",
        "description": "amount in cents (CZK haléře / EUR cents)"
       },
       "currency": {
        "type": "string",
        "description": "CZK, EUR, ..."
       }
      }
     }
    ],
    "example": {
     "refno": "48",
     "paymentId": 5531,
     "amountCents": 150000,
     "currency": "CZK",
     "login": "system@example.com",
     "at": "2026-11-27T10:15:00Z"
    }
   },
   "IsdsReceivedEvent": {
    "description": "isdsReceived – an incoming data-box message was assigned to the case",
    "allOf": [
     {
      "$ref": "#/components/schemas/EventBase"
     },
     {
      "type": "object",
      "required": [
       "msgId"
      ],
      "properties": {
       "msgId": {
        "type": "integer",
        "description": "id of the message in iSpis (isds_msg)"
       },
       "dmId": {
        "type": [
         "integer",
         "null"
        ],
        "description": "ISDS message id"
       },
       "sender": {
        "type": [
         "string",
         "null"
        ]
       }
      }
     }
    ],
    "example": {
     "refno": "48",
     "msgId": 901,
     "dmId": 1234567890,
     "sender": "Okresní soud Brno-venkov",
     "login": "system@example.com",
     "at": "2026-11-27T10:15:00Z"
    }
   },
   "Link": {
    "type": "object",
    "required": [
     "url"
    ],
    "properties": {
     "url": {
      "type": "string"
     },
     "title": {
      "type": "string"
     }
    }
   },
   "ActionResult": {
    "description": "Any JSON. Recognised shapes: a download `{ name, base64 }`; from the case\nlist `{ row }` / `{ rows, columns? }` (joined into one XLS); a message\n`{ message }`.\n",
    "oneOf": [
     {
      "type": "object",
      "required": [
       "name",
       "base64"
      ],
      "properties": {
       "name": {
        "type": "string"
       },
       "base64": {
        "type": "string",
        "contentEncoding": "base64"
       }
      }
     },
     {
      "type": "object",
      "properties": {
       "row": {
        "type": "object"
       },
       "rows": {
        "type": "array",
        "items": {
         "type": "object"
        }
       },
       "columns": {
        "type": "array",
        "items": {
         "type": "string"
        }
       },
       "message": {
        "type": "string"
       }
      }
     },
     {}
    ]
   },
   "VarResult": {
    "description": "a string, or an object whose keys are used as `[% Id.Key %]`; `{ value }` is used as the string",
    "oneOf": [
     {
      "type": "string"
     },
     {
      "type": "object"
     }
    ]
   }
  }
 }
}