网淘吧来吧,欢迎您!

Actual Budget技能使用说明

2026-03-29 新闻来源:网淘吧 围观:18
电脑广告
手机广告

Actual Budget API

官方 Node.js API 用于Actual Budget。以无头模式运行 —— 适用于从服务器同步的本地预算数据。

安装

npm install @actual-app/api

环境变量

变量必需描述
ACTUAL_SERVER_URL服务器 URL(例如,https://actual.example.com
ACTUAL_PASSWORD服务器密码
ACTUAL_SYNC_ID预算同步 ID(设置 → 高级 → 同步 ID)
ACTUAL_DATA_DIR预算数据的本地缓存目录(默认为当前工作目录)
ACTUAL_ENCRYPTION_PASSWORD端到端加密密码(如启用)
NODE_EXTRA_CA_CERTS自签名证书的CA证书文件路径

自签名证书

如果您的Actual Budget服务器使用自签名证书:

  1. 推荐:将您的CA添加到系统信任存储区,或
  2. 备选方案:设置NODE_EXTRA_CA_CERTS=/path/to/your-ca.pem以信任您的特定CA

避免完全禁用TLS验证——这会暴露您于中间人攻击的风险。

快速入门

const api = require('@actual-app/api');

await api.init({
  dataDir: process.env.ACTUAL_DATA_DIR || '/tmp/actual-cache',
  serverURL: process.env.ACTUAL_SERVER_URL,
  password: process.env.ACTUAL_PASSWORD,
});

await api.downloadBudget(
  process.env.ACTUAL_SYNC_ID,
  process.env.ACTUAL_ENCRYPTION_PASSWORD ? { password: process.env.ACTUAL_ENCRYPTION_PASSWORD } : undefined
);

// ... do work ...

await api.shutdown();

核心概念

  • 金额是以分为单位的整数:$50.00=5000,-1200费用:12.00美元
  • 日期使用YYYY-MM-DD 格式,月份使用YYYY-MM 格式
  • ID为UUID格式——可通过getIDByName(type, name)按名称查询
  • 使用api.utils.amountToInteger(123.45)转换

12345

常用操作

const months = await api.getBudgetMonths();        // ['2026-01', '2026-02', ...]
const jan = await api.getBudgetMonth('2026-01');   // { categoryGroups, incomeAvailable, ... }

获取预算概览

const accounts = await api.getAccounts();
const balance = await api.getAccountBalance(accountId);
const newId = await api.createAccount({ name: 'Checking', type: 'checking' }, 50000); // $500 initial
await api.closeAccount(id, transferToAccountId);  // transfer remaining balance

账户

// Get transactions for date range
const txns = await api.getTransactions(accountId, '2026-01-01', '2026-01-31');

// Import with deduplication + rules (preferred for bank imports)
const { added, updated } = await api.importTransactions(accountId, [
  { date: '2026-01-15', amount: -2500, payee_name: 'Grocery Store', notes: 'Weekly run' },
  { date: '2026-01-16', amount: -1200, payee_name: 'Coffee Shop', imported_id: 'bank-123' },
]);

// Update a transaction
await api.updateTransaction(txnId, { category: categoryId, cleared: true });

交易

const categories = await api.getCategories();
const groups = await api.getCategoryGroups();
const payees = await api.getPayees();

// Create
const catId = await api.createCategory({ name: 'Subscriptions', group_id: groupId });
const payeeId = await api.createPayee({ name: 'Netflix', category: catId });

类别与收款方

await api.setBudgetAmount('2026-01', categoryId, 30000);  // budget $300
await api.setBudgetCarryover('2026-01', categoryId, true);

预算金额

const rules = await api.getRules();
await api.createRule({
  stage: 'pre',
  conditionsOp: 'and',
  conditions: [{ field: 'payee', op: 'is', value: payeeId }],
  actions: [{ op: 'set', field: 'category', value: categoryId }],
});

规则

const schedules = await api.getSchedules();
await api.createSchedule({
  payee: payeeId,
  account: accountId,
  amount: -1500,
  date: { frequency: 'monthly', start: '2026-01-01', interval: 1, endMode: 'never' },
});

计划

await api.runBankSync({ accountId });  // GoCardless/SimpleFIN

银行同步

await api.sync();      // push/pull changes to server
await api.shutdown();  // always call when done

同步与关闭

ActualQL 查询

const { q, runQuery } = require('@actual-app/api');

// Sum expenses by category this month
const { data } = await runQuery(
  q('transactions')
    .filter({
      date: [{ $gte: '2026-01-01' }, { $lte: '2026-01-31' }],
      amount: { $lt: 0 },
    })
    .groupBy('category.name')
    .select(['category.name', { total: { $sum: '$amount' } }])
);

// Search transactions
const { data } = await runQuery(
  q('transactions')
    .filter({ 'payee.name': { $like: '%grocery%' } })
    .select(['date', 'amount', 'payee.name', 'category.name'])
    .orderBy({ date: 'desc' })
    .limit(20)
);

运算符: $eq$lt$lte$gt$gte$ne$oneof$regex$like$notlike 拆分选项: .options({ splits: 'inline' | 'grouped' | 'all' })

辅助功能

// Look up ID by name
const acctId = await api.getIDByName('accounts', 'Checking');
const catId = await api.getIDByName('categories', 'Food');
const payeeId = await api.getIDByName('payees', 'Amazon');

// List budgets
const budgets = await api.getBudgets();  // local + remote files

转账

转账使用特殊的收款方。通过transfer_acct字段查找转账收款方:

const payees = await api.getPayees();
const transferPayee = payees.find(p => p.transfer_acct === targetAccountId);
await api.importTransactions(fromAccountId, [
  { date: '2026-01-15', amount: -10000, payee: transferPayee.id }
]);

拆分交易

await api.importTransactions(accountId, [{
  date: '2026-01-15',
  amount: -5000,
  payee_name: 'Costco',
  subtransactions: [
    { amount: -3000, category: groceryCatId },
    { amount: -2000, category: householdCatId },
  ]
}]);

批量导入(新建预算)

从其他应用迁移:

await api.runImport('My-New-Budget', async () => {
  for (const acct of myData.accounts) {
    const id = await api.createAccount(acct);
    await api.addTransactions(id, myData.transactions.filter(t => t.acctId === id));
  }
});

参考文档

完整API:https://actualbudget.org/docs/api/referenceActualQL:https://actualbudget.org/docs/api/actual-ql

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏
文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第326323名访客 今日有221篇新文章/评论