Skip to content

Twinfield CLI

twf is Twinfield on the command line. Log in once, then list your offices, send XML requests, or use the same login in your PHP tests, examples and scripts.

Twinfield CLI is a Composer package. It needs PHP 8.3 or newer.

Terminal window
composer require --dev solvebeam/twinfield-cli

Composer puts the command in vendor/bin/twf. vendor/bin/twinfield is the same command under its long name.

Terminal window
vendor/bin/twf login

This opens the Twinfield login in your browser and stores the login on your machine. You do not need a Twinfield client ID: by default the login goes through Twinfield Connect.

On a machine without a browser, for example over SSH, use twf login --manual.

Terminal window
vendor/bin/twf status
vendor/bin/twf office list
vendor/bin/twf process-xml request.xml --office=1000

The manual has a page for each command.

Credentials::default() gives the PHP Twinfield SDK the login of twf login. Your code does not need to know about OAuth.

use SolveBeam\Twinfield\Cli\Credentials;
use SolveBeam\Twinfield\Twinfield;
$twinfield = Twinfield::create(Credentials::default());
foreach ($twinfield->offices()->list() as $office) {
echo $office->code, ' ', $office->name, PHP_EOL;
}

It works like gcloud auth application-default login, aws sso login or gh auth login: the command line tool stores the login, and your code picks it up.

  • Tests and examples that call the live Twinfield API.
  • Scripts you run yourself, such as an import or a report.
  • CI, with environment variables instead of the login.

In an application where users log in themselves, use solvebeam/twinfield-connect or solvebeam/oauth2-twinfield and store the refresh tokens yourself.

Made by SolveBeam

Twinfield and Wolters Kluwer are trademarks of Wolters Kluwer. Their names and logos are used only to refer to their products.