An example of how I use the API for punches:
http://localhost:8085/api/soap/punch.php?user=1
If I type that in the web browser it will record a punch for user 1. I have automated this with the new jscript support in v5.
The script looks like this:
Note this example is setup for only 2 test employees, Jesse and Melissa
function punch(employee){
if (employee == 'Jesse'){
var user = 2;
}
else if (employee == 'Melissa'){
var user = 12;
}
var url = 'http://localhost:8085/api/soap/punch.php?user='+user;
web.Download(url);
}
Here is the punch.php:
This file is put inside your timetrex/api/soap folder in your Timetrex installation.
<?php
require_once('../../classes/modules/api/client/TimeTrexClientAPI.class.php');
/*
Global variables
*/
$TIMETREX_URL = 'http://localhost:8085/api/soap/api.php';
$TIMETREX_USERNAME = 'USERNAME';
$TIMETREX_PASSWORD = 'PASSWORD';
$api_session = new TimeTrexClientAPI();
$api_session->Login( $TIMETREX_USERNAME, $TIMETREX_PASSWORD );
if ( $TIMETREX_SESSION_ID == FALSE ) {
echo "Login Failed!
\n";
exit;
}
echo "Session ID: $TIMETREX_SESSION_ID
\n";
$punch_obj = new TimeTrexClientAPI( 'Punch' );
$punch_data = array(
'user_id' => $_GET["user"],
'station_id' => 1,
'type_id' => 10,
//'status_id' => 10, //status type of in 10 , out 20
//'created_by' => 1,
'time_stamp' => time()
);
try{
$result = $punch_obj->setPunch( $punch_data );
if ( $result->isValid() === TRUE ) {
echo "Punch added successfully.
\n";
$insert_id = $result->getResult(); //Get punch new ID on success.
} else {
echo "Punch save failed.
\n";
print $result; //Show error messages
}
}catch(Exception $e){
echo $e->getMessage();
}
?>