getPunch() API all of sudden returning bad data

Discussion for TimeTrex open source community developers.
Post Reply
brianoneal
Posts: 2
Joined: Fri Apr 13, 2018 9:01 am

getPunch() API all of sudden returning bad data

Post by brianoneal » Fri Apr 13, 2018 11:48 am

We've been using the getPunch() api call for a while, with no issues. Today, all of sudden, there is no data returned json/array. Just a true of false. Nothing has changed in our code or the system. Last night at 5pm all is great as usual. 9am next morning all calls to getPunch() stopped working.

Did something change with the API's? :?:

Totally puzzled!!! :

mikeb
Posts: 291
Joined: Thu Jul 27, 2006 11:58 am

Re: getPunch() API all of sudden returning bad data

Post by mikeb » Fri Apr 13, 2018 12:24 pm


brianoneal
Posts: 2
Joined: Fri Apr 13, 2018 9:01 am

Re: getPunch() API all of sudden returning bad data

Post by brianoneal » Fri Apr 13, 2018 2:47 pm

I am using the TimeTrex Community (v11.2.1). PHP 5.6.33. Windows Server 2008R2 / IIS7. We are running Timetrex from your cloud. We created a web front-end for user punch-in/out. All has worked fine, including calling getPunch(), until yesterday.

Here's what getPunch() used to return:
Array ( [0] => Array ( [id] => 11e83c40-b4c5-b5e0-ade4-6b5d06ebb0d9 [user_id] => 11e80c21-6cce-4ac0-af79-6b5d06ebb0d9 [transfer] => [type_id] => 10 [type] => Normal [status_id] => 10 [status] => In [time_stamp] => 04-08-18 2:37 PM [punch_date] => 04-08-18 [punch_time] => 2:37 PM [punch_control_id] => 11e83c40-b4c3-43c0-b28f-6b5d06ebb0d9 [actual_time_stamp] => 04-08-18 2:37 PM [original_time_stamp] => 04-08-18 2:37 PM [schedule_id] => [station_id] => [station_station_id] => [station_type_id] => [station_type] => [station_source] => [station_description] => [longitude] => [latitude] => [position_accuracy] => [first_name] => Brian [last_name] => ONeal [user_status_id] => 10 [group_id] => 00000000-0000-0000-0000-000000000000 [group] => [title_id] => 11e83116-b3b4-95e0-8862-6b5d06ebb0d9 [title] => Information Technology [default_branch_id] => 11e832a3-e540-24a0-827b-6b5d06ebb0d9 [default_branch] => AdminHQ [default_department_id] => 11e832a3-18a1-b020-bfd0-6b5d06ebb0d9 [default_department] => AdminHQAdmin [date_stamp] => 04-08-18 [user_date_id] => [pay_period_id] => 11e83968-2dd2-6290-80ae-6b5d06ebb0d9 [branch_id] => 11e832a3-e540-24a0-827b-6b5d06ebb0d9 [branch] => AdminHQ [department_id] => 11e832a3-18a1-b020-bfd0-6b5d06ebb0d9 [department] => AdminHQAdmin [job_id] => 00000000-0000-0000-0000-000000000000 [job] => [job_item_id] => 00000000-0000-0000-0000-000000000000 [job_item] => [quantity] => 0 [bad_quantity] => 0 [meal_policy_id] => [note] => [other_id1] => [other_id2] => [other_id3] => [other_id4] => [other_id5] => [tainted] => [has_image] => [deleted] => [is_owner] => 1 [is_child] => [created_by_id] => 11e80c21-6cce-4ac0-af79-6b5d06ebb0d9 [created_by] => Brian C. ONeal [created_date] => 04-09-18 5:55 PM [updated_by_id] => 11e80c21-6cce-4ac0-af79-6b5d06ebb0d9 [updated_by] => Brian C. ONeal [updated_date] => 04-09-18 5:55 PM )

Now it only returns:
1

Code that we've been using for weeks that always returned the array shown above (and stopped as of yesterday):
$TIMETREX_URL = 'https://ondemand2002.timetrex.com/api/json/api.php';
$TIMETREX_USERNAME = "boneal";
$TIMETREX_PASSWORD = "password";

$arguments = array('user_name' => $TIMETREX_USERNAME, 'password' => $TIMETREX_PASSWORD );
$TIMETREX_SESSION_ID = postToURL( buildURL( 'APIAuthentication', 'Login' ), $arguments );
if ( $TIMETREX_SESSION_ID == FALSE ) {
echo "Login Failed!<br>";
exit;
}

//GET EMPLOYEE NUMBER FROM LOGIN FORM.
$arguments = array( 'filter_data' => array('employee_number' => 4499) //Use $_POST["empnumber"] from form
);

// GET ALL EMPLOYEE PUNCH DATA // WORKS FINE
$user_data = postToURL( buildURL( 'APIUser', 'getUser' ), array( $arguments ) );
echo "User ID is<b>: ".$user_data[0]['id']."</b> Name: <b>".$user_data[0]['last_name']."</b><br>";

// GET/DISPLAY USER TIMESHEET DATA for the date range based on todays date // WORKS FINE
echo "<br>----------getTimeSheetDates() data is below this line------------<br>";
$arguments = array( 'filter_data' => array('id' => $user_data[0]['id']));
$timesheetdata = postToURL( buildURL( 'APIPunch', 'getTimeSheetDates' ), '4-8-18' ); //Change hardcoded date to current system date
echo "Timesheet for Week of <b> ".$timesheetdata['start_display_date']."</b> to <b>".$timesheetdata['end_display_date']."</b><br>";
print_r($timesheetdata);

// THIS NEXT API CALL BELOW ALWAYS WORKED IN THE PAST. IT STOPPED WORKING AS OF YESTERDAY AND THERE WERE NO CHANGES MADE TO ANYTHING ANYWHERE. VERY STRANGE!!!
echo "<br><br>----------getPunch() data is below this line-------------------<br>";
$rx_punchdata = postToURL( buildURL( 'APIPunch', 'getPunch' ), array( $theUser ), array('filter_data' => array('date_stamp' => '4-8-18')) );
echo "Employee: <b>".$rx_punchdata[0]['last_name']."</b> Punch: <b>".$rx_punchdata[0]['status']." @ ".$rx_punchdata[0]['punch_time']."</b><br>";
print_r($rx_punchdata);

mikeb
Posts: 291
Joined: Thu Jul 27, 2006 11:58 am

Re: getPunch() API all of sudden returning bad data

Post by mikeb » Sat Apr 14, 2018 10:22 am

I'm not 100% sure what you are trying to do, but this code seems incorrect on several levels:

Code: Select all

$rx_punchdata = postToURL( buildURL( 'APIPunch', 'getPunch' ), array( $theUser ), array('filter_data' => array('date_stamp' => '4-8-18')) );
1. You are passing two arrays as separate arguments, which isn't correct, the server only sees the 2nd argument.

2. getPunch() doesn't accept 'date_stamp' as a filter, it accepts a date range instead using 'start_date' and 'end_date'.

3. Not sure why you are calling getPunch() at all here, it is intended to return a large list of punches over a longer period of time, if you just want to get the last punch information use:

Code: Select all

getUserPunch( $user_id = NULL, $epoch = NULL )
$epoch is the current time of the punch you intend to save, or can be omitted to use the current time instead. This is a helper function and will return smart default information for the punch.

You can then make any changes to the data from getUserPunch() and submit it back with:

Code: Select all

setPunch( $data )

Post Reply