Xero Accounting Skill
Interact with Xero accounting software via CLI. Manage invoices, contacts, payments, bank transactions, and more. All commands output JSON for easy parsing.
Script Directory
Agent: Determine this SKILL.md file's directory as SKILL_DIR, then run commands with:
CODEBLOCK0
Setup
1. Get Xero Credentials
Users need a Xero Developer account with API credentials:
- 1. Go to developer.xero.com/app/manage
- Create a Web App
- Set redirect URI: INLINECODE1
- Copy the Client ID and Client Secret
Note: If you see a scopes configuration page, add: openid, offline_access, accounting.contacts, accounting.settings, accounting.invoices, accounting.payments, accounting.banktransactions, accounting.attachments. If no scopes page is shown, that's fine - scopes are requested during OAuth.
Agent note: If credentials are missing, ask the user for their Client ID and Secret.
2. Configure OpenClaw
Add credentials to openclaw.json:
CODEBLOCK1
3. Authenticate
CODEBLOCK2
This opens a browser for OAuth. Once complete, verify with:
CODEBLOCK3
Quick Reference
Command prefix: INLINECODE11
Authentication
| Command | Description |
|---|
| INLINECODE12 | Start OAuth flow (opens browser) |
| INLINECODE13 |
Check authentication status |
|
auth logout | Clear stored credentials |
Organizations
| Command | Description |
|---|
| INLINECODE15 | List connected Xero organizations |
| INLINECODE16 |
Switch active organization |
Invoices
| Command | Description |
|---|
| INLINECODE17 | List all invoices |
| INLINECODE18 |
Filter by status |
|
invoices list --contact <id> | Filter by contact |
|
invoices get <id> | Get invoice details |
|
invoices create --contact <id> --items '<json>' | Create invoice |
|
invoices update <id> --status AUTHORISED | Update status |
Statuses: DRAFT, AUTHORISED, PAID, INLINECODE26
Types: ACCREC (sales), ACCPAY (bills)
Contacts
| Command | Description |
|---|
| INLINECODE29 | List all contacts |
| INLINECODE30 |
Search by name |
|
contacts list --customers | Only customers |
|
contacts list --suppliers | Only suppliers |
|
contacts get <id> | Get contact details |
|
contacts create --name "X" --email "Y" | Create contact |
Accounts
| Command | Description |
|---|
| INLINECODE35 | List all accounts |
| INLINECODE36 |
Filter by type |
|
accounts list --class EXPENSE | Filter by class |
|
accounts get <id> | Get account details |
Types: BANK, REVENUE, EXPENSE, FIXED, CURRENT, LIABILITY, EQUITY, etc.
Classes: ASSET, EQUITY, EXPENSE, LIABILITY, INLINECODE50
Bank Transactions
| Command | Description |
|---|
| INLINECODE51 | List all transactions |
| INLINECODE52 |
Filter by type |
|
banktransactions get <id> | Get details |
|
banktransactions create ... | Create transaction |
|
banktransactions attach <id> <file> | Attach file |
Types: SPEND, RECEIVE, RECEIVE-OVERPAYMENT, INLINECODE59
Payments
| Command | Description |
|---|
| INLINECODE60 | List all payments |
| INLINECODE61 |
Filter by invoice |
|
payments get <id> | Get payment details |
|
payments create ... | Create payment |
|
payments delete <id> | Void payment |
Allocations
| Command | Description |
|---|
| INLINECODE65 | List overpayments |
| INLINECODE66 |
List prepayments |
|
allocations list-creditnotes | List credit notes |
|
allocations overpayment -o <id> -i <inv> -a <amt> | Apply overpayment |
|
allocations prepayment -p <id> -i <inv> -a <amt> | Apply prepayment |
|
allocations creditnote -c <id> -i <inv> -a <amt> | Apply credit note |
Examples
Create an Invoice
CODEBLOCK4
Record a Payment
CODEBLOCK5
Create a Contact
CODEBLOCK6
Record Bank Transaction with Receipt
CODEBLOCK7
Error Handling
Errors return JSON:
CODEBLOCK8
Common errors:
| Error | Solution |
|---|
| Not authenticated | Run INLINECODE71 |
| Token expired |
Run
auth login again |
| No organization selected | Run
tenants list then
tenants select <id> |
Security Notes
Token Storage: OAuth tokens are saved to data/tokens.json in the working directory. This file contains sensitive access/refresh tokens - treat it as you would other credentials.
Environment Variables: The skill reads XERO_CLIENT_ID and XERO_CLIENT_SECRET from environment (set via OpenClaw config). Optional: XERO_REDIRECT_URI (default: http://localhost:5001/callback) and XERO_SCOPES.
Source Code: All skill code is bundled in the scripts/ directory for inspection. Review before granting access to production Xero organizations.
Xero 会计技能
通过命令行界面与 Xero 会计软件交互。管理发票、联系人、付款、银行交易等。所有命令均输出 JSON 格式,便于解析。
脚本目录
代理: 确定此 SKILL.md 文件的目录为 SKILL_DIR,然后使用以下命令运行:
bash
npx -y bun ${SKILL_DIR}/scripts/cli.ts <命令>
设置
1. 获取 Xero 凭证
用户需要拥有 Xero 开发者账户及 API 凭证:
- 1. 访问 developer.xero.com/app/manage
- 创建一个 Web 应用
- 设置重定向 URI:http://localhost:5001/callback
- 复制 客户端 ID 和 客户端密钥
注意:如果看到作用域配置页面,请添加:openid、offline_access、accounting.contacts、accounting.settings、accounting.invoices、accounting.payments、accounting.banktransactions、accounting.attachments。如果没有显示作用域页面,也没关系——作用域会在 OAuth 过程中请求。
代理提示: 如果缺少凭证,请向用户询问其客户端 ID 和密钥。
2. 配置 OpenClaw
将凭证添加到 openclaw.json:
json
{
skills: {
xero: {
env: {
XEROCLIENTID: 你的客户端ID,
XEROCLIENTSECRET: 你的客户端密钥
}
}
}
}
3. 身份验证
bash
npx -y bun ${SKILL_DIR}/scripts/cli.ts auth login
此命令会打开浏览器进行 OAuth 认证。完成后,使用以下命令验证:
bash
npx -y bun ${SKILL_DIR}/scripts/cli.ts auth status
快速参考
命令前缀: npx -y bun ${SKILL_DIR}/scripts/cli.ts
身份验证
| 命令 | 描述 |
|---|
| auth login | 启动 OAuth 流程(打开浏览器) |
| auth status |
检查身份验证状态 |
| auth logout | 清除存储的凭证 |
组织
| 命令 | 描述 |
|---|
| tenants list | 列出已连接的 Xero 组织 |
| tenants select <id> |
切换活动组织 |
发票
| 命令 | 描述 |
|---|
| invoices list | 列出所有发票 |
| invoices list --status AUTHORISED |
按状态筛选 |
| invoices list --contact
| 按联系人筛选 |
| invoices get | 获取发票详情 |
| invoices create --contact --items | 创建发票 |
| invoices update --status AUTHORISED | 更新状态 |
状态: DRAFT(草稿)、AUTHORISED(已授权)、PAID(已付款)、VOIDED(已作废)
类型: ACCREC(销售)、ACCPAY(采购)
联系人
| 命令 | 描述 |
|---|
| contacts list | 列出所有联系人 |
| contacts list --search 名称 |
按名称搜索 |
| contacts list --customers | 仅显示客户 |
| contacts list --suppliers | 仅显示供应商 |
| contacts get | 获取联系人详情 |
| contacts create --name X --email Y | 创建联系人 |
账户
| 命令 | 描述 |
|---|
| accounts list | 列出所有账户 |
| accounts list --type REVENUE |
按类型筛选 |
| accounts list --class EXPENSE | 按类别筛选 |
| accounts get | 获取账户详情 |
类型: BANK(银行)、REVENUE(收入)、EXPENSE(费用)、FIXED(固定资产)、CURRENT(流动资产)、LIABILITY(负债)、EQUITY(权益)等。
类别: ASSET(资产)、EQUITY(权益)、EXPENSE(费用)、LIABILITY(负债)、REVENUE(收入)
银行交易
| 命令 | 描述 |
|---|
| banktransactions list | 列出所有交易 |
| banktransactions list --type SPEND |
按类型筛选 |
| banktransactions get | 获取详情 |
| banktransactions create ... | 创建交易 |
| banktransactions attach <文件> | 附加文件 |
类型: SPEND(支出)、RECEIVE(收款)、RECEIVE-OVERPAYMENT(收款多付)、SPEND-OVERPAYMENT(支出多付)
付款
| 命令 | 描述 |
|---|
| payments list | 列出所有付款 |
| payments list --invoice <id> |
按发票筛选 |
| payments get | 获取付款详情 |
| payments create ... | 创建付款 |
| payments delete | 作废付款 |
分配
| 命令 | 描述 |
|---|
| allocations list-overpayments | 列出多付款项 |
| allocations list-prepayments |
列出预付款项 |
| allocations list-creditnotes | 列出贷项通知单 |
| allocations overpayment -o -i <发票> -a <金额> | 应用多付款项 |
| allocations prepayment -p -i <发票> -a <金额> | 应用预付款项 |
| allocations creditnote -c -i <发票> -a <金额> | 应用贷项通知单 |
示例
创建发票
bash
1. 查找联系人
npx -y bun ${SKILL_DIR}/scripts/cli.ts contacts list --search Acme
2. 获取收入账户代码
npx -y bun ${SKILL_DIR}/scripts/cli.ts accounts list --type REVENUE
3. 创建发票
npx -y bun ${SKILL_DIR}/scripts/cli.ts invoices create \
--contact <联系人ID> \
--items [{description:咨询服务,quantity:10,unitAmount:150,accountCode:200}] \
--reference INV-001
4. 准备就绪后授权
npx -y bun ${SKILL_DIR}/scripts/cli.ts invoices update <发票ID> --status AUTHORISED
记录付款
bash
1. 获取银行账户 ID
npx -y bun ${SKILL_DIR}/scripts/cli.ts accounts list --type BANK
2. 创建付款(将发票标记为已付款)
npx -y bun ${SKILL_DIR}/scripts/cli.ts payments create \
--invoice <发票ID> \
--account <银行账户ID> \
--amount 500.00 \
--reconciled
创建联系人
bash
npx -y bun ${SKILL_DIR}/scripts/cli.ts contacts create \
--name Acme 公司 \
--email billing@acme.com \
--customer
记录带收据的银行交易
bash
1. 创建交易
npx -y bun ${SKILL_DIR}/scripts/cli.ts banktransactions create \
--type RECEIVE \
--bank-account <银行ID> \
--contact <联系人ID> \
--items [{description:付款,unitAmount:500,accountCode:200}]
2. 附加收据
npx -y bun ${SKILL_DIR}/scripts/cli.ts banktransactions attach <交易ID> ./receipt.pdf
错误处理
错误返回 JSON 格式:
json
{error: 未认证。请运行 auth login}
常见错误:
| 错误 | 解决方案 |
|---|
| 未认证 | 运行 auth login |
| 令牌已过期 |
再次运行 auth login |
| 未选择组织 | 运行 tenants list,然后运行 tenants select |
安全说明
令牌存储: OAuth 令牌保存到工作目录中的 data/tokens.json 文件。此文件包含敏感的访问/刷新令牌——请像对待其他凭证一样对待它。
环境变量: 该技能从环境变量中读取 XERO_CLIENT