CLI tool for managing FreshBooks invoices, clients, and billing. Uses the official @freshbooks/api SDK.
npm install -g @haseebuchiha/freshbooks-cli
Requires .npmrc with @haseebuchiha:registry=https://npm.pkg.github.com for GitHub Package Registry.
Authenticate with FreshBooks OAuth2. You must use the --manual flag (localhost redirect does not work with FreshBooks).
freshbooks auth login \
--client-id "<FRESHBOOKS_CLIENT_ID>" \
--client-secret "<FRESHBOOKS_CLIENT_SECRET>" \
--manual
This opens the browser. Authorize, then copy the code from the page and paste it into the CLI. Tokens are stored at ~/.config/freshbooks-cli/config.json (0600 permissions) and auto-refresh before expiry.
Verify: freshbooks auth status
freshbooks auth login --client-id --client-secret --manual -- authenticate via OAuth2 OOB flowfreshbooks auth logout -- clear stored tokens and credentialsfreshbooks auth status -- show account ID, token expiry, and auth statefreshbooks auth refresh -- manually refresh the access tokenfreshbooks clients list [-p ] [--per-page ] [-s ] -- list clients, search by org namefreshbooks clients get -- get a single client by IDfreshbooks clients create [--fname ] [--lname ] [--email ] [--organization ] -- create a clientfreshbooks clients create --data '' -- create with full JSON payloadfreshbooks clients update --data '' -- update a clientExample: freshbooks clients create --fname "Taha" --organization "abcg.io"
freshbooks invoices list [-p ] [--per-page ] -- list invoicesfreshbooks invoices get -- get a single invoice by IDfreshbooks invoices create --client-id [--lines ''] -- create an invoice with line itemsfreshbooks invoices create --client-id --data '' -- create with full JSON payloadfreshbooks invoices update --data '' -- update an invoicefreshbooks invoices archive -- archive an invoice (no permanent delete in FreshBooks)freshbooks invoices share-link -- get a shareable link for an invoiceLines are a JSON array. Each line has name, qty, and unitCost (money object):
[
{"name": "Web Services", "qty": 1, "unitCost": {"amount": "15000.00", "code": "USD"}},
{"name": "App Services", "qty": 1, "unitCost": {"amount": "15000.00", "code": "USD"}}
]
Example (full invoice create):
freshbooks invoices create --client-id 818183 \
--lines '[{"name":"Web Services","qty":1,"unitCost":{"amount":"15000.00","code":"USD"}},{"name":"App Services","qty":1,"unitCost":{"amount":"15000.00","code":"USD"}}]'
freshbooks clients create --fname "Name" --organization "Company" -- note the returned idfreshbooks invoices create --client-id --lines '[...]' -- create the invoicefreshbooks invoices share-link -- get shareable linkfreshbooks clients list -s "company name" -- find the client IDfreshbooks invoices list -- list all invoices (filter by client in output)freshbooks invoices get -- get full invoice detailsjq for filtering: freshbooks clients list | jq '.clients[].organization'{"amount": "string", "code": "USD"}. The amount is always a string like "30000.00", never a number. Do not use parseFloat on money.archive sets vis_state=1. FreshBooks does not support permanent deletion.freshbooks auth login --client-id --client-secret --manual .FRESHBOOKS_CLIENT_ID and FRESHBOOKS_CLIENT_SECRET (takes priority over stored config).--manual for auth login. The localhost callback redirect URI does not work with FreshBooks.共 1 个版本