{
  "openapi": "3.1.0",
  "info": {
    "title": "Central API",
    "version": "1",
    "summary": "Search, read and file documents and emails in your company's Central server from your own systems.",
    "description": "The API runs on your company's own Central server, at https://<your server>/api/v1. Make a key on the dashboard (Company → API access) and send it as `Authorization: Bearer cfk_...`.\n\nA **person key** acts as one of your people: send their email address (as listed under Company → People) in the `X-On-Behalf-Of` header on every call, and they get exactly what their own Windows permissions let them open. A **company key** acts as nobody in particular: it can list locations, count, and file, but never read documents.\n\nIds of documents carry the server that holds them (`<server>.<id>`): keep them as they are. A document's id is made from its path, so it stays the same until the file is moved or renamed.\n\nErrors are problem details (RFC 9457) with a `code`: `key`, `licence`, `api-off`, `browser`, `address`, `daily-limit`, `scope`, `needs-person`, `person`, `argument`, `not-found`, `already-filed`, `offline`, `search`.\n\nWithin v1 only things are added (new fields, endpoints, optional parameters): ignore fields you don't know.",
    "license": { "name": "Proprietary" }
  },
  "servers": [ { "url": "https://{server}/api/v1", "variables": { "server": { "default": "your-server.example.com", "description": "Your Central server's address (Company → API access shows it)." } } } ],
  "security": [ { "key": [] } ],
  "tags": [
    { "name": "About", "description": "This server and this key." },
    { "name": "Search", "description": "Search, read and download, as the person the key acts for." },
    { "name": "Filing", "description": "File documents and emails into the company's locations." }
  ],
  "paths": {
    "/": {
      "get": {
        "tags": [ "About" ], "operationId": "about", "summary": "This server, this key and what it may do",
        "responses": { "200": { "description": "About this server and key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/About" } } } }, "default": { "$ref": "#/components/responses/Problem" } }
      }
    },
    "/locations": {
      "get": {
        "tags": [ "Search" ], "operationId": "listLocations", "summary": "The indexed locations on each server (scope locations.read)",
        "parameters": [ { "$ref": "#/components/parameters/Person" }, { "$ref": "#/components/parameters/Server" } ],
        "responses": { "200": { "description": "Each server's locations", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Locations" } } } }, "default": { "$ref": "#/components/responses/Problem" } }
      }
    },
    "/search": {
      "get": {
        "tags": [ "Search" ], "operationId": "search", "summary": "Search documents and emails (scope search)",
        "description": "With several servers, each page holds up to `limit` results from each server (ordered together by date when `sort=date`).",
        "parameters": [
          { "$ref": "#/components/parameters/Person" }, { "$ref": "#/components/parameters/Server" },
          { "$ref": "#/components/parameters/Q" }, { "$ref": "#/components/parameters/AnyWord" }, { "$ref": "#/components/parameters/FileName" }, { "$ref": "#/components/parameters/Content" },
          { "$ref": "#/components/parameters/Subject" }, { "$ref": "#/components/parameters/From" }, { "$ref": "#/components/parameters/To" }, { "$ref": "#/components/parameters/AttachmentName" },
          { "$ref": "#/components/parameters/AttachmentContent" }, { "$ref": "#/components/parameters/Folder" }, { "$ref": "#/components/parameters/Types" }, { "$ref": "#/components/parameters/Kind" },
          { "$ref": "#/components/parameters/HasAttachments" }, { "$ref": "#/components/parameters/After" }, { "$ref": "#/components/parameters/Before" },
          { "name": "sort", "in": "query", "schema": { "type": "string", "enum": [ "relevance", "date", "name", "size", "sender", "subject" ] }, "description": "Default relevance (newest first when there are no words)." },
          { "name": "newestFirst", "in": "query", "schema": { "type": "boolean", "default": true } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 50, "default": 25 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "minimum": 0, "maximum": 10000, "default": 0 } }
        ],
        "responses": { "200": { "description": "Results", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SearchResults" } } } }, "default": { "$ref": "#/components/responses/Problem" } }
      }
    },
    "/documents/{id}": {
      "get": {
        "tags": [ "Search" ], "operationId": "getDocument", "summary": "A document's details and attachments (scope documents.read)",
        "parameters": [ { "$ref": "#/components/parameters/Person" }, { "$ref": "#/components/parameters/Id" } ],
        "responses": { "200": { "description": "The document", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Document" } } } }, "default": { "$ref": "#/components/responses/Problem" } }
      }
    },
    "/documents/{id}/text": {
      "get": {
        "tags": [ "Search" ], "operationId": "getDocumentText", "summary": "A document's text, a part at a time (scope documents.read)",
        "description": "For an email: its headers, body and the text of its attachments. Pass `nextOffset` back as `offset` for the next part.",
        "parameters": [
          { "$ref": "#/components/parameters/Person" }, { "$ref": "#/components/parameters/Id" },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "minimum": 0, "default": 0 } },
          { "name": "max", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100000, "default": 20000 } }
        ],
        "responses": { "200": { "description": "The text", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Text" } } } }, "default": { "$ref": "#/components/responses/Problem" } }
      }
    },
    "/documents/{id}/file": {
      "get": {
        "tags": [ "Search" ], "operationId": "downloadDocument", "summary": "The original file, or an attachment (scope files.read)",
        "description": "Large files are streamed; `Range` requests are honoured.",
        "parameters": [ { "$ref": "#/components/parameters/Person" }, { "$ref": "#/components/parameters/Id" } ],
        "responses": { "200": { "description": "The file", "content": { "application/octet-stream": { "schema": { "type": "string", "format": "binary" } } } }, "206": { "description": "Part of the file" }, "default": { "$ref": "#/components/responses/Problem" } }
      }
    },
    "/counts": {
      "get": {
        "tags": [ "Search" ], "operationId": "counts", "summary": "Totals grouped by type, folder, sender, month or year (scope counts)",
        "parameters": [
          { "$ref": "#/components/parameters/Person" }, { "$ref": "#/components/parameters/Server" },
          { "name": "by", "in": "query", "required": true, "schema": { "type": "string", "enum": [ "extension", "kind", "folder", "sender", "month", "year" ] } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 200, "default": 25 } },
          { "$ref": "#/components/parameters/Q" }, { "$ref": "#/components/parameters/AnyWord" }, { "$ref": "#/components/parameters/FileName" }, { "$ref": "#/components/parameters/Content" },
          { "$ref": "#/components/parameters/Subject" }, { "$ref": "#/components/parameters/From" }, { "$ref": "#/components/parameters/To" }, { "$ref": "#/components/parameters/AttachmentName" },
          { "$ref": "#/components/parameters/AttachmentContent" }, { "$ref": "#/components/parameters/Folder" }, { "$ref": "#/components/parameters/Types" }, { "$ref": "#/components/parameters/Kind" },
          { "$ref": "#/components/parameters/HasAttachments" }, { "$ref": "#/components/parameters/After" }, { "$ref": "#/components/parameters/Before" }
        ],
        "responses": { "200": { "description": "Counts", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Counts" } } } }, "default": { "$ref": "#/components/responses/Problem" } }
      }
    },
    "/destinations": {
      "get": {
        "tags": [ "Filing" ], "operationId": "listDestinations", "summary": "Where things can be filed: each server's locations (scope filing.write)",
        "parameters": [ { "$ref": "#/components/parameters/Person" } ],
        "responses": { "200": { "description": "Locations to file into", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Destinations" } } } }, "default": { "$ref": "#/components/responses/Problem" } }
      }
    },
    "/folders": {
      "get": {
        "tags": [ "Filing" ], "operationId": "listFolders", "summary": "Folders of a location: under a folder, or found by name (scope filing.write)",
        "parameters": [
          { "$ref": "#/components/parameters/Person" },
          { "name": "server", "in": "query", "required": true, "schema": { "type": "string" }, "description": "serverId from /destinations." },
          { "name": "destination", "in": "query", "required": true, "schema": { "type": "string" }, "description": "id from /destinations." },
          { "name": "path", "in": "query", "schema": { "type": "string" }, "description": "A folder inside the location (e.g. Clients/Smith); empty: its top." },
          { "name": "q", "in": "query", "schema": { "type": "string", "minLength": 2 }, "description": "Find folders by name (a job number, a client) instead of listing." }
        ],
        "responses": { "200": { "description": "Folders", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Folders" } } } }, "default": { "$ref": "#/components/responses/Problem" } }
      }
    },
    "/filing": {
      "post": {
        "tags": [ "Filing" ], "operationId": "file", "summary": "File a document or an email (.eml) into a folder (scope filing.write)",
        "description": "Saved by the server that owns the location, like anything filed from Outlook: the company's file names, Windows permissions (as the person, for a person key), and an email is never filed twice. Answers 202 at once; follow it with GET /filing/{jobId}.",
        "parameters": [ { "$ref": "#/components/parameters/Person" } ],
        "requestBody": {
          "required": true,
          "content": { "multipart/form-data": { "schema": {
            "type": "object", "required": [ "server", "destination", "file" ],
            "properties": {
              "server": { "type": "string", "description": "serverId from /destinations." },
              "destination": { "type": "string", "description": "id from /destinations." },
              "folder": { "type": "string", "description": "An existing folder inside the location, e.g. Clients/Smith (from /folders); empty: the top of the location." },
              "externalId": { "type": "string", "maxLength": 200, "description": "Your own id for this item: sending it again gives the first job back instead of a second copy." },
              "subject": { "type": "string", "description": "For a document: what Filing history shows (default: the file's name)." },
              "file": { "type": "string", "format": "binary", "description": "One file. An .eml is filed as an email." }
            } } } }
        },
        "responses": {
          "202": { "description": "Queued", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Filed" } } } },
          "200": { "description": "Already sent with this externalId: the first job", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Filed" } } } },
          "409": { "description": "This email has already been filed (code already-filed)", "content": { "application/problem+json": { "schema": { "$ref": "#/components/schemas/Problem" } } } },
          "default": { "$ref": "#/components/responses/Problem" }
        }
      }
    },
    "/filing/{jobId}": {
      "get": {
        "tags": [ "Filing" ], "operationId": "getFiling", "summary": "How a filing made by this key is going (scope filing.write)",
        "parameters": [ { "$ref": "#/components/parameters/Person" }, { "name": "jobId", "in": "path", "required": true, "schema": { "type": "string" } } ],
        "responses": { "200": { "description": "Its state", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Job" } } } }, "default": { "$ref": "#/components/responses/Problem" } }
      }
    },
    "/filing/check": {
      "get": {
        "tags": [ "Filing" ], "operationId": "checkFiled", "summary": "Whether an email is filed already, and where (scope filing.write)",
        "parameters": [ { "$ref": "#/components/parameters/Person" }, { "name": "messageId", "in": "query", "required": true, "schema": { "type": "string" }, "description": "The email's Message-ID, with or without angle brackets." } ],
        "responses": { "200": { "description": "Filed or not", "content": { "application/json": { "schema": { "type": "object", "properties": { "filed": { "type": "boolean" }, "filings": { "type": "array", "items": { "$ref": "#/components/schemas/Filing" } } } } } } }, "default": { "$ref": "#/components/responses/Problem" } }
      }
    }
  },
  "components": {
    "securitySchemes": { "key": { "type": "http", "scheme": "bearer", "description": "An API key from Company → API access (cfk_...)." } },
    "parameters": {
      "Person": { "name": "X-On-Behalf-Of", "in": "header", "schema": { "type": "string", "format": "email" }, "description": "Person keys: the email address of the person the call is for (one of the company's People). Company keys: leave it out." },
      "Server": { "name": "server", "in": "query", "schema": { "type": "string" }, "description": "Only this server (an id from /locations); default: every server the key may use." },
      "Id": { "name": "id", "in": "path", "required": true, "schema": { "type": "string" }, "description": "A document id from search results (or an attachment id from a document)." },
      "Q": { "name": "q", "in": "query", "schema": { "type": "string" }, "description": "Words in the name, text, subject and attachment names; all must appear unless anyWord. \"A phrase\" in quotes; from:smith and subject:invoice work too." },
      "AnyWord": { "name": "anyWord", "in": "query", "schema": { "type": "boolean" } },
      "FileName": { "name": "fileName", "in": "query", "schema": { "type": "string" } },
      "Content": { "name": "content", "in": "query", "schema": { "type": "string" }, "description": "Words in the text only." },
      "Subject": { "name": "subject", "in": "query", "schema": { "type": "string" } },
      "From": { "name": "from", "in": "query", "schema": { "type": "string" }, "description": "An email's sender (name or address)." },
      "To": { "name": "to", "in": "query", "schema": { "type": "string" }, "description": "An email's To or Cc." },
      "AttachmentName": { "name": "attachmentName", "in": "query", "schema": { "type": "string" } },
      "AttachmentContent": { "name": "attachmentContent", "in": "query", "schema": { "type": "string" }, "description": "Words inside an email's attached files." },
      "Folder": { "name": "folder", "in": "query", "schema": { "type": "string" }, "description": "Only this folder and below, as results show it (e.g. \\\\fs1\\projects\\Smith)." },
      "Types": { "name": "types", "in": "query", "schema": { "type": "string" }, "description": "File extensions, comma separated: pdf, docx." },
      "Kind": { "name": "kind", "in": "query", "schema": { "type": "string", "enum": [ "email", "document", "image" ] } },
      "HasAttachments": { "name": "hasAttachments", "in": "query", "schema": { "type": "boolean" } },
      "After": { "name": "after", "in": "query", "schema": { "type": "string", "format": "date" }, "description": "From this day (an email's sent date, otherwise the file's modified date)." },
      "Before": { "name": "before", "in": "query", "schema": { "type": "string", "format": "date" }, "description": "Up to and including this day." }
    },
    "responses": {
      "Problem": { "description": "Refused or failed", "content": { "application/problem+json": { "schema": { "$ref": "#/components/schemas/Problem" } } } }
    },
    "schemas": {
      "Problem": { "type": "object", "properties": { "type": { "type": "string" }, "title": { "type": "string" }, "status": { "type": "integer" }, "code": { "type": "string" } } },
      "About": { "type": "object", "properties": {
        "api": { "type": "string" }, "server": { "type": "string" }, "company": { "type": "string" },
        "key": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "mode": { "type": "string", "enum": [ "person", "company" ] }, "scopes": { "type": "array", "items": { "type": "string" } }, "expires": { "type": "string", "format": "date-time" } } },
        "search": { "type": "boolean" }, "filing": { "type": "boolean" }, "windowsPermissions": { "type": "boolean" } } },
      "ServerState": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "total": { "type": "integer" }, "error": { "type": "string" } } },
      "Locations": { "type": "object", "properties": { "servers": { "type": "array", "items": { "type": "object", "properties": {
        "id": { "type": "string" }, "name": { "type": "string" }, "online": { "type": "boolean" }, "indexing": { "type": "boolean" }, "error": { "type": "string" },
        "locations": { "type": "array", "items": { "type": "object", "properties": { "path": { "type": "string" }, "documents": { "type": "integer" }, "includesSubfolders": { "type": "boolean" } } } } } } } } },
      "Hit": { "type": "object", "properties": {
        "id": { "type": "string" }, "serverId": { "type": "string" }, "server": { "type": "string" }, "name": { "type": "string" }, "kind": { "type": "string", "enum": [ "email", "document", "image" ] },
        "extension": { "type": "string" }, "folder": { "type": "string" }, "path": { "type": "string" }, "webUrl": { "type": "string" }, "date": { "type": "string", "format": "date-time" },
        "size": { "type": "integer" }, "subject": { "type": "string" }, "from": { "type": "string" }, "to": { "type": "string" },
        "attachments": { "type": "array", "items": { "type": "string" } }, "snippet": { "type": "string", "description": "The matching words in **bold**." } } },
      "SearchResults": { "type": "object", "properties": {
        "total": { "type": "integer" }, "offset": { "type": "integer" }, "limit": { "type": "integer" }, "more": { "type": "boolean" },
        "indexing": { "type": "boolean", "description": "A server is still indexing: results may be incomplete." },
        "servers": { "type": "array", "items": { "$ref": "#/components/schemas/ServerState" } }, "results": { "type": "array", "items": { "$ref": "#/components/schemas/Hit" } } } },
      "Document": { "type": "object", "properties": {
        "id": { "type": "string" }, "server": { "type": "string" }, "name": { "type": "string" }, "kind": { "type": "string" }, "extension": { "type": "string" }, "path": { "type": "string" },
        "date": { "type": "string", "format": "date-time" }, "size": { "type": "integer" }, "subject": { "type": "string" }, "from": { "type": "string" }, "to": { "type": "string" }, "cc": { "type": "string" },
        "attachments": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "size": { "type": "integer" } } } },
        "characters": { "type": "integer", "description": "How long its text is." }, "note": { "type": "string" } } },
      "Text": { "type": "object", "properties": {
        "id": { "type": "string" }, "offset": { "type": "integer" }, "returned": { "type": "integer" }, "total": { "type": "integer" }, "nextOffset": { "type": [ "integer", "null" ] },
        "truncated": { "type": "boolean" }, "note": { "type": "string" }, "text": { "type": "string" } } },
      "Counts": { "type": "object", "properties": {
        "by": { "type": "string" }, "total": { "type": "integer" }, "counted": { "type": "integer" }, "note": { "type": "string" },
        "groups": { "type": "array", "items": { "type": "object", "properties": { "key": { "type": "string" }, "count": { "type": "integer" } } } },
        "servers": { "type": "array", "items": { "$ref": "#/components/schemas/ServerState" } } } },
      "Destinations": { "type": "object", "properties": { "destinations": { "type": "array", "items": { "type": "object", "properties": {
        "serverId": { "type": "string" }, "server": { "type": "string" }, "online": { "type": "boolean" }, "id": { "type": "string" }, "name": { "type": "string" },
        "kind": { "type": "string", "enum": [ "FileSystem", "SharePoint", "OneDrive" ] } } } } } },
      "Folders": { "type": "object", "properties": { "error": { "type": "string" }, "folders": { "type": "array", "items": { "type": "object", "properties": {
        "name": { "type": "string" }, "path": { "type": "string" }, "hasChildren": { "type": "boolean" }, "canFile": { "type": "boolean", "description": "false: the person may see it but not file into it." } } } } } },
      "Filed": { "type": "object", "properties": { "jobId": { "type": "string" }, "status": { "type": "string" }, "duplicate": { "type": "boolean" } } },
      "Place": { "type": "object", "properties": { "serverId": { "type": "string" }, "destination": { "type": "string" }, "folder": { "type": "string" },
        "status": { "type": "string", "enum": [ "queued", "saving", "filed", "failed", "undone" ] }, "error": { "type": "string" }, "savedAs": { "type": "array", "items": { "type": "string" } } } },
      "Job": { "type": "object", "properties": { "jobId": { "type": "string" }, "created": { "type": "string", "format": "date-time" }, "subject": { "type": "string" },
        "status": { "type": "string", "enum": [ "queued", "saving", "filed", "failed", "undone" ] }, "places": { "type": "array", "items": { "$ref": "#/components/schemas/Place" } } } },
      "Filing": { "type": "object", "properties": { "at": { "type": "string", "format": "date-time" }, "by": { "type": "string" }, "places": { "type": "array", "items": { "$ref": "#/components/schemas/Place" } } } }
    }
  }
}
