{
  "openapi": "3.1.0",
  "info": {
    "title": "WealthTrackr Personal Data API",
    "version": "1.1.0",
    "description": "REST API for your personal financial data from WealthTrackr. Create and revoke API keys from Settings → Personal API access in the app. Keys are read-only by default; a key created with write access can also create, edit and delete expenses. Keys can be revoked at any time.",
    "contact": {
      "name": "Apercall LLC",
      "url": "https://github.com/apercallc/wealthtrackr",
      "email": "security@apercallc.com"
    }
  },
  "servers": [
    {
      "url": "https://server-production-c1e82.up.railway.app",
      "description": "Production API"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Send your API key (wtk_...) as a Bearer token."
      },
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Send your API key (wtk_...) via the X-API-Key header."
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    },
    {
      "apiKeyHeader": []
    }
  ],
  "paths": {
    "/v1/data/summary": {
      "get": {
        "tags": [
          "data"
        ],
        "summary": "Financial summary",
        "description": "Net worth, asset/liability totals and counts, latest snapshot, and as_of timestamp.",
        "responses": {
          "200": {
            "description": "Financial summary",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "net_worth": {
                      "type": "number",
                      "description": "Total assets minus total liabilities"
                    },
                    "total_assets": {
                      "type": "number"
                    },
                    "total_liabilities": {
                      "type": "number"
                    },
                    "asset_count": {
                      "type": "integer"
                    },
                    "liability_count": {
                      "type": "integer"
                    },
                    "latest_snapshot": {
                      "type": "object",
                      "nullable": true,
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "month": {
                          "type": "string",
                          "pattern": "^\\d{4}-(0[1-9]|1[0-2])$"
                        },
                        "net_worth": {
                          "type": "number"
                        },
                        "total_assets": {
                          "type": "number"
                        },
                        "total_liabilities": {
                          "type": "number"
                        },
                        "category_breakdown": {
                          "type": "object"
                        },
                        "notes": {
                          "type": "string",
                          "nullable": true
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    },
                    "as_of": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, or revoked API key"
          }
        }
      }
    },
    "/v1/data/items": {
      "get": {
        "tags": [
          "data"
        ],
        "summary": "Account categories and items",
        "description": "Account categories and items, including ownership-adjusted effective_value.",
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asset",
                "liability"
              ]
            },
            "description": "Filter account categories by type."
          }
        ],
        "responses": {
          "200": {
            "description": "Categories with items",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          },
                          "type": {
                            "type": "string",
                            "enum": [
                              "asset",
                              "liability"
                            ]
                          },
                          "total": {
                            "type": "number"
                          },
                          "items": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string"
                                },
                                "label": {
                                  "type": "string"
                                },
                                "value": {
                                  "type": "number"
                                },
                                "ownership_percentage": {
                                  "type": "number"
                                },
                                "effective_value": {
                                  "type": "number",
                                  "description": "value * (ownership_percentage / 100)"
                                },
                                "liquidity_rating": {
                                  "type": "string",
                                  "enum": [
                                    "high",
                                    "medium",
                                    "low"
                                  ]
                                },
                                "notes": {
                                  "type": "string",
                                  "nullable": true
                                },
                                "last_updated": {
                                  "type": "string",
                                  "format": "date-time"
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, or revoked API key"
          },
          "422": {
            "description": "Invalid query parameter"
          }
        }
      }
    },
    "/v1/data/snapshots": {
      "get": {
        "tags": [
          "data"
        ],
        "summary": "Monthly net-worth snapshots",
        "description": "Monthly net-worth snapshots, newest first.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            },
            "description": "Number of snapshots to return (1–1000). Defaults to all."
          },
          {
            "name": "since",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-(0[1-9]|1[0-2])$"
            },
            "description": "Only snapshots for this month (YYYY-MM) or later."
          }
        ],
        "responses": {
          "200": {
            "description": "Snapshots list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "snapshots": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "month": {
                            "type": "string",
                            "pattern": "^\\d{4}-(0[1-9]|1[0-2])$"
                          },
                          "net_worth": {
                            "type": "number"
                          },
                          "total_assets": {
                            "type": "number"
                          },
                          "total_liabilities": {
                            "type": "number"
                          },
                          "category_breakdown": {
                            "type": "object"
                          },
                          "notes": {
                            "type": "string",
                            "nullable": true
                          },
                          "timestamp": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, or revoked API key"
          }
        }
      }
    },
    "/v1/data/metrics": {
      "get": {
        "tags": [
          "data"
        ],
        "summary": "Monthly financial check-ins",
        "description": "Returns the newest entry in 'latest' and all entries newest-first in 'history'. Credit score and each monthly money metric are independently optional; every supplied value is returned, and a record must contain at least one score or money metric. Calculated fields (debt_to_income_ratio, monthly_cash_flow, savings_rate) are null when their required inputs were not recorded.",
        "responses": {
          "200": {
            "description": "Monthly metrics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "latest": {
                      "type": "object",
                      "nullable": true,
                      "properties": {
                        "month": {
                          "type": "string",
                          "pattern": "^\\d{4}-(0[1-9]|1[0-2])$"
                        },
                        "credit_score": {
                          "type": "integer",
                          "nullable": true,
                          "minimum": 300,
                          "maximum": 850,
                          "description": "Optional credit score; a record may instead contain monthly money metrics."
                        },
                        "monthly_income": {
                          "type": "number",
                          "nullable": true
                        },
                        "monthly_expenses": {
                          "type": "number",
                          "nullable": true
                        },
                        "monthly_debt_payments": {
                          "type": "number",
                          "nullable": true
                        },
                        "monthly_savings": {
                          "type": "number",
                          "nullable": true
                        },
                        "retirement_savings": {
                          "type": "number",
                          "nullable": true
                        },
                        "debt_to_income_ratio": {
                          "type": "number",
                          "nullable": true,
                          "description": "(monthly_debt_payments / monthly_income) * 100, or null"
                        },
                        "monthly_cash_flow": {
                          "type": "number",
                          "nullable": true,
                          "description": "monthly_income - monthly_expenses, or null"
                        },
                        "savings_rate": {
                          "type": "number",
                          "nullable": true,
                          "description": "(monthly_savings / monthly_income) * 100, or null"
                        },
                        "updated_at": {
                          "type": "string",
                          "nullable": true
                        }
                      }
                    },
                    "history": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "month": {
                            "type": "string"
                          },
                          "credit_score": {
                            "type": "integer",
                            "nullable": true,
                            "minimum": 300,
                            "maximum": 850
                          },
                          "monthly_income": {
                            "type": "number",
                            "nullable": true
                          },
                          "monthly_expenses": {
                            "type": "number",
                            "nullable": true
                          },
                          "monthly_debt_payments": {
                            "type": "number",
                            "nullable": true
                          },
                          "monthly_savings": {
                            "type": "number",
                            "nullable": true
                          },
                          "retirement_savings": {
                            "type": "number",
                            "nullable": true
                          },
                          "debt_to_income_ratio": {
                            "type": "number",
                            "nullable": true
                          },
                          "monthly_cash_flow": {
                            "type": "number",
                            "nullable": true
                          },
                          "savings_rate": {
                            "type": "number",
                            "nullable": true
                          },
                          "updated_at": {
                            "type": "string",
                            "nullable": true
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, or revoked API key"
          }
        }
      }
    },
    "/v1/data/expenses/{expense_id}": {
      "put": {
        "tags": [
          "data"
        ],
        "summary": "Replace an expense",
        "description": "Requires a write-scoped API key. Changes appear on every device at its next sync.",
        "parameters": [
          {
            "name": "expense_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "description",
                  "amount",
                  "currency",
                  "category",
                  "date"
                ],
                "properties": {
                  "description": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "amount": {
                    "type": "number",
                    "exclusiveMinimum": 0,
                    "description": "In the currency's own precision (e.g. 2 decimals; JPY none)"
                  },
                  "currency": {
                    "type": "string",
                    "description": "ISO 4217 code: USD, EUR, GBP, JPY, CAD, AUD, CHF, CNY, INR, MXN"
                  },
                  "category": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 40
                  },
                  "date": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                  },
                  "notes": {
                    "type": "string",
                    "nullable": true,
                    "maxLength": 240
                  },
                  "id": {
                    "type": "string",
                    "maxLength": 128,
                    "description": "POST only. Optional client-chosen id; reusing one returns 409."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The saved expense",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "description": {
                      "type": "string"
                    },
                    "amount": {
                      "type": "number",
                      "description": "Positive amount in the record's own currency"
                    },
                    "currency": {
                      "type": "string",
                      "description": "ISO 4217 code"
                    },
                    "category": {
                      "type": "string"
                    },
                    "date": {
                      "type": "string",
                      "nullable": true,
                      "description": "YYYY-MM-DD"
                    },
                    "notes": {
                      "type": "string",
                      "nullable": true
                    },
                    "updated_at": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, or revoked API key"
          },
          "403": {
            "description": "The API key is read-only"
          },
          "404": {
            "description": "Expense not found"
          },
          "422": {
            "description": "Invalid expense"
          }
        }
      },
      "delete": {
        "tags": [
          "data"
        ],
        "summary": "Delete an expense",
        "description": "Requires a write-scoped API key. A tombstone is kept so other devices cannot resurrect the expense.",
        "parameters": [
          {
            "name": "expense_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing, malformed, or revoked API key"
          },
          "403": {
            "description": "The API key is read-only"
          },
          "404": {
            "description": "Expense not found"
          },
          "422": {
            "description": "Invalid expense"
          }
        }
      }
    },
    "/v1/data/expenses": {
      "post": {
        "tags": [
          "data"
        ],
        "summary": "Create an expense",
        "description": "Requires a write-scoped API key. Appears on every signed-in device at its next sync.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "description",
                  "amount",
                  "currency",
                  "category",
                  "date"
                ],
                "properties": {
                  "description": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "amount": {
                    "type": "number",
                    "exclusiveMinimum": 0,
                    "description": "In the currency's own precision (e.g. 2 decimals; JPY none)"
                  },
                  "currency": {
                    "type": "string",
                    "description": "ISO 4217 code: USD, EUR, GBP, JPY, CAD, AUD, CHF, CNY, INR, MXN"
                  },
                  "category": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 40
                  },
                  "date": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
                  },
                  "notes": {
                    "type": "string",
                    "nullable": true,
                    "maxLength": 240
                  },
                  "id": {
                    "type": "string",
                    "maxLength": 128,
                    "description": "POST only. Optional client-chosen id; reusing one returns 409."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The saved expense",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "description": {
                      "type": "string"
                    },
                    "amount": {
                      "type": "number",
                      "description": "Positive amount in the record's own currency"
                    },
                    "currency": {
                      "type": "string",
                      "description": "ISO 4217 code"
                    },
                    "category": {
                      "type": "string"
                    },
                    "date": {
                      "type": "string",
                      "nullable": true,
                      "description": "YYYY-MM-DD"
                    },
                    "notes": {
                      "type": "string",
                      "nullable": true
                    },
                    "updated_at": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, or revoked API key"
          },
          "403": {
            "description": "The API key is read-only"
          },
          "409": {
            "description": "Duplicate id, or the 10,000-expense limit was reached"
          },
          "422": {
            "description": "Invalid expense"
          }
        }
      },
      "get": {
        "tags": [
          "data"
        ],
        "summary": "Expense ledger",
        "description": "Individual expense records, newest first. Deleted records are never returned. Amounts are in each record's own currency and are not converted.",
        "parameters": [
          {
            "name": "start",
            "in": "query",
            "description": "Inclusive start date (YYYY-MM-DD)",
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "end",
            "in": "query",
            "description": "Inclusive end date (YYYY-MM-DD)",
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "currency",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 3,
              "maxLength": 3
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "description": "ISO timestamp; only records changed after it",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000,
              "default": 100
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of expenses",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "expenses": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "amount": {
                            "type": "number",
                            "description": "Positive amount in the record's own currency"
                          },
                          "currency": {
                            "type": "string",
                            "description": "ISO 4217 code"
                          },
                          "category": {
                            "type": "string"
                          },
                          "date": {
                            "type": "string",
                            "nullable": true,
                            "description": "YYYY-MM-DD"
                          },
                          "notes": {
                            "type": "string",
                            "nullable": true
                          },
                          "updated_at": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, or revoked API key"
          },
          "422": {
            "description": "Invalid query parameter"
          }
        }
      }
    },
    "/v1/data/expenses/summary": {
      "get": {
        "tags": [
          "data"
        ],
        "summary": "Spending summary",
        "description": "Spending totals by currency, month and category. Currencies are never mixed.",
        "parameters": [
          {
            "name": "start",
            "in": "query",
            "description": "Inclusive start date",
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          {
            "name": "end",
            "in": "query",
            "description": "Inclusive end date",
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Spending summary",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer"
                    },
                    "totals": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "currency": {
                            "type": "string"
                          },
                          "total": {
                            "type": "number"
                          }
                        }
                      }
                    },
                    "by_month": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "currency": {
                            "type": "string"
                          },
                          "month": {
                            "type": "string",
                            "description": "YYYY-MM"
                          },
                          "total": {
                            "type": "number"
                          }
                        }
                      }
                    },
                    "by_category": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "currency": {
                            "type": "string"
                          },
                          "category": {
                            "type": "string"
                          },
                          "total": {
                            "type": "number"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, or revoked API key"
          }
        }
      }
    },
    "/v1/data/income": {
      "get": {
        "tags": [
          "data"
        ],
        "summary": "Income records",
        "description": "One-off and recurring income records, newest first.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000,
              "default": 100
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of income records",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "income": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "amount": {
                            "type": "number",
                            "description": "Positive amount in the record's own currency"
                          },
                          "currency": {
                            "type": "string",
                            "description": "ISO 4217 code"
                          },
                          "category": {
                            "type": "string"
                          },
                          "date": {
                            "type": "string",
                            "nullable": true,
                            "description": "YYYY-MM-DD"
                          },
                          "notes": {
                            "type": "string",
                            "nullable": true
                          },
                          "updated_at": {
                            "type": "string"
                          },
                          "recurring": {
                            "type": "string",
                            "nullable": true
                          },
                          "start_date": {
                            "type": "string",
                            "nullable": true
                          },
                          "end_date": {
                            "type": "string",
                            "nullable": true
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, or revoked API key"
          }
        }
      }
    },
    "/v1/data/goals": {
      "get": {
        "tags": [
          "data"
        ],
        "summary": "Financial goals",
        "description": "Goals exactly as the apps store them, plus updated_at. Field names inside a goal follow the app (camelCase).",
        "responses": {
          "200": {
            "description": "Goals",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "goals": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, malformed, or revoked API key"
          }
        }
      }
    }
  }
}