Create time entry
Saves the time and kilometres a user wrote on a project and an activity on one day.
Twinfield documentation: Time entry.
This example changes data in Twinfield with
--save. Only run it on a test administration: the Twinfield documentation has no way to delete a time entry through the API.
A time entry has a header (the kind of entry, the user, the date, the project and the activity) and lines:
time($duration, …)adds a time line, with an optionaldescription,billableandrate.quantity($quantity, …)adds a quantity line, e.g. kilometres, with an optionalrateandbillable. The quantity is a numeric string ('12.5'), never a float.
TimeEntryInput::direct() is time on a project; indirect() and personal() are for time that is not for a customer, such as a meeting or leave.
Twinfield creates the entry when it does not exist yet and updates it otherwise. save() returns a TimeEntry with what Twinfield added: the names, the rate of each line and its internal and external value. To save several entries in one request, e.g. a whole week, use saveMany(): it returns a result per entry and does not throw when some are refused.
Without --save the example only shows the XML it would send.
$twinfield = Example::twinfield();
// E.g. `JDOE P0099 A010`: the user the time is for, a project and an activity of the company.$arguments = array_values(array_filter( array_slice($argv ?? [], 1), static fn (string $argument): bool => $argument !== '--save',));[$user, $project, $activity] = array_pad($arguments, 3, null);
if ($user === null || $project === null || $activity === null) { echo 'Usage: php example.php <user> <project> <activity> [--save]', PHP_EOL;
exit(0);}
// Four units of time and 12.5 kilometres on one day. Twinfield takes the rates and whether the// lines are billable from the project and the activity, unless you pass them.$input = TimeEntryInput::direct($user, new DateTimeImmutable('today'), $project, $activity) ->time(240, description: 'Implementation') ->quantity('12.5');
if (!in_array('--save', $argv ?? [], true)) { echo 'Dry run; add --save to save the time entry (it can\'t be deleted through the API):', PHP_EOL, PHP_EOL; echo Example::xml(TimeEntryXmlWriter::request((string) $twinfield->companyCode(), $input)), PHP_EOL;
exit(0);}
try { $entry = $twinfield->timeEntries()->save($input);} catch (ProcessXmlException $exception) { foreach ($exception->result->messages() as $message) { echo $message->type->value, ' at ', $message->path, ': ', $message->text, PHP_EOL; }
exit(1);}
echo 'Saved: ', $entry->type->value, ' ', $entry->date->format('Y-m-d'), ' ', $entry->user->code, ' on ', $entry->project?->code ?? '-', ' / ', $entry->activity?->code ?? '-', PHP_EOL;
foreach ($entry->timeLines as $line) { echo ' ', $line->id, ' time ', $line->duration, ' at ', $line->rate->code, ': ', $line->internalValue, ' internal, ', $line->externalValue, ' external ', $line->currency, $line->billable ? ', billable' : '', PHP_EOL;}
foreach ($entry->quantityLines as $line) { echo ' ', $line->id, ' quantity ', $line->quantity, ' at ', $line->rate->code, ': ', $line->internalValue, ' internal, ', $line->externalValue, ' external ', $line->currency, $line->billable ? ', billable' : '', PHP_EOL;}php examples/time-entries/create-time-entry/example.php JDOE P0099 A010The write guard of the examples blocks changes unless you allow them for a company in TWINFIELD_WRITE_COMPANIES:
TWINFIELD_COMPANY=1002_3 TWINFIELD_ALLOW_WRITES=1002_3 php examples/time-entries/create-time-entry/example.php JDOE P0099 A010 --saveThe output below follows the documentation; it was not run live yet.
Saved: DIRECT 2026-11-10 JDOE on P0099 / A010 1 time 240 at T001: 240.00 internal, 400.00 external EUR, billable 2 quantity 12.5 at KM: 125.00 internal, 250.00 external EURWhat the SDK sends to Twinfield and what Twinfield sends back, for a call like the one in this example. The responses come from the tests, with example data.
Create/Update
Section titled “Create/Update”Twinfield documentation: Time entry: Create/Update.
$twinfield->timeEntries()->save( TimeEntryInput::direct('JDOE', new DateTimeImmutable('2026-11-10'), 'P0099', 'A010') ->time(240, description: 'Deploy') ->quantity('1.5'),);The SDK sends this XML as xmlRequest of ProcessXmlString to processxml.asmx:
<teqs> <teq> <header> <office>1000</office> <code>DIRECT</code> <user>JDOE</user> <date>20261110</date> <prj1>P0099</prj1> <prj2>A010</prj2> </header> <lines> <line type="TIME"> <duration>240</duration> <description>Deploy</description> </line> <line type="QUANTITY"> <value1>1.5</value1> </line> </lines> </teq></teqs>Twinfield answers with this XML in ProcessXmlStringResult:
<teqs result="1"> <teq result="1"> <header> <office>1000</office> <code>DIRECT</code> <user name="John Doe" shortname="John">JDOE</user> <date>20261110</date> <prj1 name="API documentation" shortname="API documentation">P0099</prj1> <prj2 name="Deploy API documentation" shortname="API documentation">A010</prj2> <accountsreceivable>1010</accountsreceivable> <authoriser name="Site supervisor" result="1" shortname="Site supervisor">SUPER</authoriser> </header> <lines> <line type="TIME" id="1"> <duration internal="240.00" external="400.00">240</duration> <description>Deploy</description> <billable>1</billable> <ratecode internal="15.00" external="25.00" units="15.00" name="Normal rate" shortname="Normal rate">T001</ratecode> <currency>EUR</currency> </line> <line type="QUANTITY" id="2"> <value1 internal="15.00" external="30.00">1.5</value1> <ratecode1 internal="10.00" external="20.00" units="1" name="KM" shortname="KM">KM</ratecode1> <currency1>EUR</currency1> <billable1>0</billable1> </line> </lines> </teq></teqs>Source
Section titled “Source”View examples/time-entries/create-time-entry/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.