Skip to content

Examples

Small, self-contained examples. Each folder shows one thing, with an example.php you can run and a README.md that explains it.

  1. Register http://localhost:8765/callback as redirect URI for your client in the Twinfield developer portal.

  2. Run any example, for instance:

    Terminal window
    php examples/offices/list-offices/example.php

The first time, the example asks for your client ID, client secret and redirect URI, opens the Twinfield login in your browser and asks for a default company. Everything is saved in ~/.config/twinfield/, so after that examples start right away. Run composer twinfield:setup to change these values.

Every example starts the same way:

require __DIR__ . '/../../../vendor/autoload.php';
$twinfield = Example::twinfield();

In your own application you create the client yourself: see Authentication.

Add TWINFIELD_DEBUG=1 to any example to see the SOAP requests and responses.

  • Login: let a user log in and get the refresh token.
  • Authentication: create a client in your own application.
  • Token info: organisation, user and cluster of an access token.
  • Error handling: catch errors and act on their code.
  • List periods: years of the company and the periods of a year.
  • Rename period: change a period with a command (changes data).