# Overview

EntryTarget exposes a RESTful JSON API over HTTP.

## Base URL

```
http://<your-host>:<port>
```

The port is configured via the `LEDGER_PORT` environment variable.

## Authentication

All routes (except `/health`, `/metrics`, and `POST /credentials`) require authentication via two headers:

```
X-Api-Key:    ak_...
X-Api-Secret: sk_...
```

See [Authentication](/docs/api-reference/authentication.md) for details on how to obtain and manage credentials.

## Content Type

All request bodies must be JSON:

```
Content-Type: application/json
```

## Response Format

All responses are JSON. Successful responses return the relevant data directly. Error responses follow a consistent format:

```json
{
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable description"
  }
}
```

## Endpoint Summary

### Accounts

| Method | Route                   | Auth | Description                         |
| ------ | ----------------------- | ---- | ----------------------------------- |
| POST   | `/account`              | Yes  | Create a new account                |
| GET    | `/account/:id`          | Yes  | Get account balance and metadata    |
| GET    | `/account/:id/ledger`   | Yes  | Get account ledger (paginated)      |
| GET    | `/account/asset/:asset` | Yes  | Balance summary grouped by category |

### Transactions

| Method | Route                | Auth | Description                          |
| ------ | -------------------- | ---- | ------------------------------------ |
| POST   | `/transaction`       | Yes  | Create a new transaction             |
| GET    | `/transaction/:id`   | Yes  | Get journal entries of a transaction |
| GET    | `/journal/entry/:id` | Yes  | Get a specific journal entry         |

### Idempotency & Recovery

| Method | Route               | Auth | Description                               |
| ------ | ------------------- | ---- | ----------------------------------------- |
| GET    | `/idempotency/:key` | Yes  | Get original request/response for a key   |
| GET    | `/recovery`         | Yes  | Get last-batch records for crash recovery |

### Ledger Archive

| Method | Route                         | Auth | Description                      |
| ------ | ----------------------------- | ---- | -------------------------------- |
| POST   | `/ledger/archive`             | Yes  | Archive ledger lines             |
| GET    | `/account/:id/ledger/archive` | Yes  | Read archived ledger for account |

### Integrity

| Method | Route        | Auth | Description                              |
| ------ | ------------ | ---- | ---------------------------------------- |
| GET    | `/integrity` | Yes  | Validate row-level integrity of all data |

### Credentials

| Method | Route                   | Auth | Description               |
| ------ | ----------------------- | ---- | ------------------------- |
| POST   | `/credentials`          | No   | Register a new credential |
| DELETE | `/credentials/:api_key` | Yes  | Revoke a credential       |

### Observability

| Method | Route      | Auth | Description        |
| ------ | ---------- | ---- | ------------------ |
| GET    | `/health`  | No   | Health check       |
| GET    | `/metrics` | No   | Prometheus metrics |

## Common Patterns

### POST Responses

POST endpoints return only the essential data (IDs, balances, versions). They do **not** include `created_at` timestamps. Use the corresponding GET endpoint to retrieve timestamps when needed.

### Timestamps

All timestamps use ISO 8601 format with millisecond precision:

```
2026-01-15T10:30:00.123Z
```

### UUIDs

All identifiers are UUID v7 (sequential by time). They sort chronologically and are globally unique.

### String Normalization

All string fields (`category`, `asset`, `entry_type`) are automatically normalized to uppercase. You can send lowercase — the system converts automatically.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://entrytarget.gitbook.io/docs/api-reference/overview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
