1

I have a requirement to output the total number of hours in a given time frame using the Harvest API. I have coded in PHP but it gives an error Call to undefined method HarvestAPI::getUsersActiveTimer() The Input is the Start Date End Date Output Total Hours

This is my code

     <?php
    require_once( dirname(__FILE__) . '/HarvestAPI.php' );

    spl_autoload_register(array('HarvestAPI', 'autoload') );

    $api = new HarvestAPI();
    $api->setUser( $user );
    $api->setPassword( $password );
    $api->setAccount( $account_name );

    $api->setSSL( true );

    $result = $api->getUsersActiveTimer( $userid );

    if( $result->isSuccess() ) {
    echo "It is Successful!";
        if( ! is_null( $result->data ) ){
            echo $result->get( "started-at" );
        }
    }

else{
echo "It is not Successful";

}

?>

Kindly suggest a way to go about this

user3402248
  • 439
  • 6
  • 25

1 Answers1

1

If you take a look at the Harvest API here you will see that there is no method called getUsersActiveTimer. That may be from an older version. You may be able to use the method getUserEntries which will "get all user entries for given time range and for a particular project if specified." That may require some additional calculation within PHP, but it is a valid method so it should return some data. You will need to specify a date range. Here is a usage example from the docs:

$range = new Harvest_Range( "20090712", "20090719" );
 $project_id = 12345;
 $user_id = 11111;

 $api = new HarvestAPI();

 $result = $api->getUserEntries( $user_id, $range, $project_id );
 if( $result->isSuccess() ) {
     $dayEntries = $result->data;
     var_dump($dayEntries);
 } else {
  //no data!
}
larsAnders
  • 3,813
  • 1
  • 15
  • 19
  • I tried this, but for some reason doesn' t display any output. The data which I am working on does not have a project ID. It only contains a Time sheet with the number of hours worked each day. I would like to use this Information only. – user3402248 Apr 08 '16 at 22:35
  • Right, you can leave the project id off without problems. It says that in the API. One of the best approaches here is to slow down, go to the official docs, and read carefully. It will save both your desk and your forehead. – larsAnders Apr 08 '16 at 22:36
  • Thanks for the advice. Will do that – user3402248 Apr 08 '16 at 22:46
  • I have gone through the website about Harvest API. I can navigate through the different classes available in the Wrapper Library. But kindly tell me how can I get the names for the methods for a particular class? – user3402248 Apr 14 '16 at 17:54
  • @IarsAnders I got it. One has to click on Harvest API on the left section of the Navigation Panel which would basically list out all the methods. – user3402248 Apr 14 '16 at 19:27