indy2kro / buxfer-api
Buxfer API client library
Requires
- php: >=8.3
- guzzlehttp/guzzle: ^7.9 || ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^2
- phpstan/phpstan-phpunit: ^2
- phpstan/phpstan-strict-rules: ^2
- phpunit/phpunit: ^11 || ^12
- rector/rector: ^2
Suggests
- ext-curl: Faster HTTP transport for Guzzle than PHP streams.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-14 16:48:16 UTC
README
Buxfer API library implementation in PHP (8.3+), using the Guzzle HTTP client. Using the API requires a valid Buxfer.com account. See https://www.buxfer.com/help/api for the full API description.
composer require indy2kro/buxfer-api
Actions
login(string $username, string $password): string- log in with the Buxfer credentials (POST, the credentials are not sent in the URL); returns the token and is mandatory before any other actionlistAccounts(),listLoans(),listTags(),listBudgets(),listReminders(),listGroups(),listContacts()- return the matching listlistTransactions(array $filters = []): array- one page (at most 100) of transactions. Filters:accountIdoraccountName,tagIdortagName,startDateandendDate,budgetIdorbudgetName,contactIdorcontactName,groupIdorgroupName,status,pagelistAllTransactions(array $filters = []): array- all transactions matching the filters, following the pagination (throws if the server repeats a page or returns more thanClient::MAX_PAGESpages)addTransaction(array $transaction): array- add a transaction (transaction_add), returns the created transactioneditTransaction(array $transaction): array- change a transaction (transaction_edit);idis required, plus the fields to changedeleteTransaction(string $id): void- delete a transaction (transaction_delete)uploadStatement(array $params): array- upload a statement (upload_statement):accountIdandstatementare required,dateFormatis optional
See the Buxfer API description for the available parameters of each command.
Other methods:
__construct(array $config = [], ?GuzzleHttp\Client $httpClient = null)- the configuration is merged with the defaults; an injected HTTP client is used as isgetLastDuration(): float- duration of the last request in secondsgetToken(): string- token received after logingetConfig(): arrayandsetConfig(array $config): void- read and merge the configuration (an HTTP client built by the library is rebuilt onsetConfig())
Every error is thrown as \BuxferApi\Exception, including transport errors and invalid responses. Actions called before login() throw without sending a request.
Configuration
Supported keys, all optional and checked when set (unknown keys throw, and an invalid value leaves the configuration unchanged):
[
'user_agent' => 'PHP BuxferApi ' . Client::VERSION, // string
'timeout' => 10, // int|float, seconds, greater than 0
'handler' => null, // callable, a Guzzle handler such as a HandlerStack
]
For anything else (proxy, TLS options), build your own GuzzleHttp\Client and pass it to the constructor.
Sample usage
use BuxferApi\Client; $buxferApi = new Client(); $buxferApi->login('testuser@testaccount.com', 'testpassword'); // list existing transactions $transactions = $buxferApi->listTransactions(['accountId' => '1000000']); // add a new transaction $buxferApi->addTransaction([ 'accountId' => '1000000', 'date' => '2020-02-11', 'type' => 'expense', 'amount' => '10.20', 'description' => 'Test transaction', 'tags' => 'mytag1,mytag2', ]);
Security notes
Buxfer takes the session token as a URL query parameter, so request URLs are sensitive: do not log them or the requests of your HTTP client. The library does not pass on Guzzle exceptions, because their messages contain the request URL, and it does not follow redirects. See SECURITY.md for details and how to report a vulnerability.
Extending
The protected restRequest(), httpRequest(), authenticatedUrl() and buildHttpClient() methods are the supported extension hooks and follow semantic versioning. Other protected members are internal and may change in a minor release.
Development
composer quality # PHPUnit, PHP CS Fixer (dry run), PHPStan (max, strict rules), Rector (dry run)
composer fix # apply PHP CS Fixer and Rector
See CHANGELOG.md for changes between versions.