REST API request
Calls the Twinfield REST API directly with $twinfield->rest(), for an endpoint the SDK has no method for yet.
- The REST API identifies the company by GUID, not by code.
$twinfield->companyId()gives it: the SDK looks it up once with the Finder (OFFwithincludeid), or takes it fromcompany('1000', $guid)or anOfficeSummary. - Copy the path from the Swagger definition:
{organisationId}and{companyId}are filled in. json()returns aJsonValuewith typed readers (string(),int(),decimal(),list(), …) that throw anUnexpectedResponseExceptionwhen a value is missing or invalid. Numbers are read as exact strings, never as floats.- Without
fields=*many endpoints return only their default fields.
Every REST operation needs its own scope, here readFixedAssets; without it Twinfield answers HTTP 403. See Scopes.
$twinfield = Example::twinfield();
echo 'Company ', $twinfield->companyCode(), ' has GUID ', $twinfield->companyId(), PHP_EOL;
// A path from the Swagger definition: the SDK fills in the GUIDs of the organisation and company.$response = $twinfield->rest( 'GET', '/organisations/{organisationId}/companies/{companyId}/fixedassets/classes', ['fields' => '*', 'limit' => 5],);
$json = $response->json();
echo $json->int('filteredTotal'), ' fixed asset classes', PHP_EOL;
foreach ($json->list('items') as $class) { echo $class->string('name'), ': ', $class->string('method'), ', lifetime ', $class->decimal('lifetime'), PHP_EOL;}php examples/getting-started/rest-request/example.phpAdd TWINFIELD_DEBUG=1 to see the requests and responses.
Company 1000 has GUID ffe2c8b3-e7f0-4793-a059-ffbfe3c154a93 fixed asset classesBuildings: straightLine, lifetime 360Machines: straightLine, lifetime 60Vehicles: straightLine, lifetime 48Source
Section titled “Source”View examples/getting-started/rest-request/example.php on GitHub.
Twinfield and Wolters Kluwer are trademarks of Wolters Kluwer. Their names and logos are used only to refer to their products.