{
  "openapi": "3.1.0",
  "info": {
    "title": "ImpactiNotes Developer API",
    "version": "1.0.0",
    "description": "Read-only access to explicitly granted notes and databases. Create personal keys in Settings > Developers. Workspace grants include current and future databases and notes. Database grants include entry note bodies. Keys expire and can be revoked. Limit: 60 requests per minute per key. Responses use Cache-Control: no-store. Lists are ordered by ascending UUID and use the last returned ID as the next cursor; concurrent edits are not a snapshot."
  },
  "servers": [{ "url": "/api/v1" }],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/workspaces": {
      "get": {
        "operationId": "listWorkspaces",
        "summary": "List granted workspaces",
        "parameters": [
          { "$ref": "#/components/parameters/limit" },
          { "$ref": "#/components/parameters/after" }
        ],
        "responses": {
          "200": { "$ref": "#/components/responses/list" },
          "401": { "$ref": "#/components/responses/error" },
          "429": { "$ref": "#/components/responses/rateLimit" }
        }
      }
    },
    "/notes": {
      "get": {
        "operationId": "listNotes",
        "summary": "List granted notes with Markdown bodies",
        "parameters": [
          { "$ref": "#/components/parameters/limit" },
          { "$ref": "#/components/parameters/after" },
          { "$ref": "#/components/parameters/search" }
        ],
        "responses": {
          "200": { "$ref": "#/components/responses/list" },
          "400": { "$ref": "#/components/responses/error" },
          "401": { "$ref": "#/components/responses/error" },
          "429": { "$ref": "#/components/responses/rateLimit" }
        }
      }
    },
    "/notes/{id}": {
      "get": {
        "operationId": "getNote",
        "summary": "Read a granted note",
        "parameters": [{ "$ref": "#/components/parameters/id" }],
        "responses": {
          "200": { "$ref": "#/components/responses/item" },
          "401": { "$ref": "#/components/responses/error" },
          "404": { "$ref": "#/components/responses/error" },
          "429": { "$ref": "#/components/responses/rateLimit" }
        }
      }
    },
    "/databases": {
      "get": {
        "operationId": "listDatabases",
        "summary": "List granted databases",
        "parameters": [
          { "$ref": "#/components/parameters/limit" },
          { "$ref": "#/components/parameters/after" }
        ],
        "responses": {
          "200": { "$ref": "#/components/responses/list" },
          "401": { "$ref": "#/components/responses/error" },
          "429": { "$ref": "#/components/responses/rateLimit" }
        }
      }
    },
    "/databases/{id}": {
      "get": {
        "operationId": "getDatabase",
        "summary": "Read a database and its active property definitions",
        "parameters": [{ "$ref": "#/components/parameters/id" }],
        "responses": {
          "200": { "$ref": "#/components/responses/item" },
          "401": { "$ref": "#/components/responses/error" },
          "404": { "$ref": "#/components/responses/error" },
          "429": { "$ref": "#/components/responses/rateLimit" }
        }
      }
    },
    "/databases/{id}/query": {
      "post": {
        "operationId": "queryDatabase",
        "summary": "Read independent or note-linked rows with an optional exact-value filter",
        "description": "This POST performs no content writes. Filter uses the stable property UUID, not its display name. Values retain their JSON type. Missing values do not match an explicit null. Search matches note titles. Only equality is supported in v1.",
        "parameters": [{ "$ref": "#/components/parameters/id" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "limit": { "type": "integer", "minimum": 1, "maximum": 100, "default": 50 },
                  "after": { "type": "string", "format": "uuid" },
                  "search": { "type": "string", "maxLength": 200 },
                  "filter": {
                    "type": "object",
                    "required": ["property_id", "value"],
                    "additionalProperties": false,
                    "properties": {
                      "property_id": { "type": "string", "format": "uuid" },
                      "value": {
                        "oneOf": [
                          { "type": "string", "maxLength": 10000 },
                          { "type": "number" },
                          { "type": "boolean" },
                          { "type": "null" },
                          { "type": "array", "maxItems": 100, "items": { "type": "string" } }
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "$ref": "#/components/responses/list" },
          "400": { "$ref": "#/components/responses/error" },
          "401": { "$ref": "#/components/responses/error" },
          "404": { "$ref": "#/components/responses/error" },
          "413": { "$ref": "#/components/responses/error" },
          "429": { "$ref": "#/components/responses/rateLimit" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Personal key beginning imp_. Never put the key in the URL."
      }
    },
    "parameters": {
      "id": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "format": "uuid" }
      },
      "limit": {
        "name": "limit",
        "in": "query",
        "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 50 }
      },
      "after": { "name": "after", "in": "query", "schema": { "type": "string", "format": "uuid" } },
      "search": {
        "name": "search",
        "in": "query",
        "description": "Case-insensitive title substring",
        "schema": { "type": "string", "maxLength": 200 }
      }
    },
    "responses": {
      "list": {
        "description": "Accessible records and an optional next cursor",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": ["data", "next_cursor"],
              "properties": {
                "data": {
                  "type": "array",
                  "items": { "type": "object", "additionalProperties": true }
                },
                "next_cursor": { "type": ["string", "null"], "format": "uuid" }
              }
            }
          }
        }
      },
      "item": {
        "description": "Accessible record",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": ["data"],
              "properties": { "data": { "type": "object", "additionalProperties": true } }
            }
          }
        }
      },
      "error": {
        "description": "JSON error; ungranted resources also return 404",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": ["error"],
              "properties": {
                "error": {
                  "type": "object",
                  "required": ["code", "message"],
                  "properties": { "code": { "type": "string" }, "message": { "type": "string" } }
                }
              }
            }
          }
        }
      },
      "rateLimit": {
        "description": "Per-key rate limit exceeded",
        "headers": { "Retry-After": { "schema": { "type": "integer", "example": 60 } } },
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "code": { "const": "rate_limited" },
                    "message": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
