actual-http-api

repository·main·Indexed 42 days ago

https://github.com/jhonderson/actual-http-api

A lightweight HTTP wrapper around the Actual Budget Node.js API (version 26.9.0) that provides a RESTful interface for non-Node.js applications. It includes endpoints for managing budgets, account groups, and accounts, and exposes a Swagger UI for interactive API documentation.

Tokens
13.5K
Snippets
66
Records
80
Agent score
53%

What's inside actual-http-api

  1. Back up an Actual budget using a bash script

    main

    You can use the provided budget_backup.sh script to back up your Actual budget to a specific destination.

    To use the script, you must update the following variables within budget_backup.sh:

    • ACTUAL_BUDGET_URL: The URL of your Actual server.
    • ACTUAL_BUDGET_API_KEY: Your API key.
    • ACTUAL_BUDGET_SYNC_ID_LIST: A list of sync IDs for the budgets you wish to back up.

    After configuring the variables, grant execution permissions and run the script. You can schedule this via cron (Linux/macOS) or Task Scheduler (Windows) for automated daily backups.

    # Update these in budget_backup.sh
    ACTUAL_BUDGET_URL="..."
    ACTUAL_BUDGET_API_KEY="..."
    ACTUAL_BUDGET_SYNC_ID_LIST=("...")
    
    # Run the script
    chmod +x budget_backup.sh
    ./budget_backup.sh
  2. Local development setup

    main

    There are two ways to run the project locally:

    Option 1: Docker Compose

    Run using the provided configuration:

    docker-compose up -d

    You can adjust environment variables in the docker-compose.yml file or via an .env file.

    Option 2: Node.js

    Install dependencies and start the server directly:

    npm install
    npm start
    # or
    node server.js

    Note: The project automatically loads a .env file in the project root when NODE_ENV is not set to production.

    npm install
    npm start
  3. Quick Start — Run the public Docker image

    main

    You can deploy the service using a publicly published Docker image. This provides a REST interface to your Actual Budget server. By default, the service exposes Swagger UI at http://localhost:5007/api-docs/.

    docker run -d --name actualhttpapi \
      -v "$PWD/data:/data:rw" \
      -p 5007:5007 \
      -e ACTUAL_SERVER_URL="http://actual-server:5006/" \
      -e ACTUAL_SERVER_PASSWORD="your-actual-password" \
      -e API_KEY="your-api-key" \
      jhonderson/actual-http-api:26.2.0
  4. Update Investment Account Balances via Python script

    main

    You can automate the updating of investment account balances in Actual Budget using the update_account_balances.py script.

    Prerequisites

    • API Version: Requires actual-http-api version 26.4.0 or later.
    • Python Version: yfinance requires Python 3.9+. If using Python 3.8 or lower, install an older version: pip install "yfinance<0.2.30".

    Setup Steps

    1. Prepare your Budget: In Actual Budget, go to your investment accounts (Off budget) and add a note to each specifying holdings using the #holding syntax. Example note content:
      #holding 34.2342 VGRO.TO
      #holding 100.34 CASH
    2. Configure the Script: Update the following variables in update_account_balances.py:
      • BASE_URL: Your API base URL.
      • BUDGET_SYNC_ID: The sync ID of the budget.
      • API_TOKEN: Your API token.
      • PAYEE_NAME: (Optional) The name of the payee; defaults to empty.
    3. Install Dependencies: It is recommended to use a virtual environment.
    4. Run: Execute the script and schedule it (via cron or Task Scheduler) to run daily.
    # Using a virtual environment (recommended)
    python3 -m venv venv
    source venv/bin/activate
    pip install requests yfinance
    
    # Run the script
    python update_account_balances.py
  5. Configure environment variables

    main

    The service uses several environment variables for configuration. Secrets can be provided directly as strings or via a file path using the _PATH suffix (e.g., API_KEY_PATH).

    Required Variables

    • API_KEY or API_KEY_PATH: A secret string used to authenticate clients to this wrapper. Note: This is a wrapper-specific key, not an Actual Budget credential.
    • ACTUAL_SERVER_PASSWORD or ACTUAL_SERVER_PASSWORD_PATH: The password for your Actual server.
    • ACTUAL_SERVER_URL: The base URL of your Actual server (e.g., http://actual-server:5006/).

    Optional Variables

    • ACTUAL_DATA_DIR: Path to the Actual server data directory (for local data access).
    • PORT: Port the service listens on (Default: 5007).
    • NODE_ENV: Node environment (e.g., production, development).
    • EXPERIMENTAL_OPERATIONS_ENABLED: Boolean to enable/disable experimental endpoints that rely on Actual internals (Default: true).

    Swagger / API Docs Configuration

    Use these to adjust the documentation URL and links:

    • SWAGGER_PROTOCOL: Default https (Set to http if running locally with port mapping).
    • SWAGGER_HOST: Default localhost.
    • SWAGGER_PORT: Default 443 (Set to your service port, e.g., 5007, for local runs).
    • SWAGGER_BASE_PATH: Default v1.
  6. Accessing budget resources via budgetSyncId

    main

    Most API endpoints are scoped to a specific budget using a budgetSyncId path parameter. This ID is the Synchronization ID found in Actual Budget under Settings → Show advanced settings → Sync ID.

    To access these resources, you must include the budgetSyncId in the URL path. For example, if your sync ID is abc-123, your base path for resources like accounts or transactions would be /budgets/abc-123/accounts or /budgets/abc-123/transactions.

    Security Note: If you are using an end-to-end encrypted budget, you must provide the encryption password in the budget-encryption-password HTTP header.

    GET /budgets/:budgetSyncId/accounts
    Header: budget-encryption-password: <your-password>
  7. Deploy actual-http-api using Docker Compose

    main

    You can deploy the actual-http-api using Docker Compose. The service maps port 5007 and requires a local ./data directory for persistent storage. You must provide environment variables to connect to your Actual Budget server and secure the API.

    version: '3.3'
    services:
        actual-http-api:
            container_name: actualhttpapi
            volumes:
                - './data:/data:rw'
            ports:
                - '5007:5007'
            environment:
                - 'ACTUAL_SERVER_URL=http://localhost:5006/'
                - 'ACTUAL_SERVER_PASSWORD=my-actual-server-password'
                - 'API_KEY=my-strong-api-key'
            restart: on-failure
            image: jhonderson/actual-http-api:latest
  8. Troubleshoot server startup failures

    main
    If the server fails to start, it is most likely due to missing required secrets. Ensure that either API_KEY and ACTUAL_SERVER_PASSWORD are provided, or their file-path equivalents (API_KEY_PATH and ACTUAL_SERVER_PASSWORD_PATH) are correctly configured.
  9. Import a budget via API

    main

    The POST /v1/budgets/import endpoint allows you to import an Actual export or a YNAB4/YNAB5 file.

    Important Behavior:

    • Content-Type: Must be application/zip or application/octet-stream.
    • New Sync ID: Importing an existing budget does not overwrite it. The Actual library clears the server identity on import, so the budget is uploaded as a new file with a new sync id. The original budget remains untouched. You must use the syncId returned in the response to interact with the newly imported budget.
    curl -X POST 'http://localhost:5007/v1/budgets/import?type=actual' \
      -H 'x-api-key: your-api-key' \
      -H 'Content-Type: application/zip' \
      --data-binary '@2026-09-06-My-Budget.zip'