Using the advanced reporting functions of HarvestReports

In addition to supporting the Time Tracking and Extended REST API the Harvest api PHP interface – HaPi library has additional quick reporting functions built into the HarvestReports object. This class extends the main HarvestAPI reports with the option to get only active/inactive clients, projects, and users. In addition it contains methods for obtaining a user’s active timer, or all active timers. Below are a few quick examples of these functions, the one nice thing about the HarvestReports is that you don’t need to do any additional configurations.

Get all Active Projects

The getActiveProjects function will return only the active projects from your Harvest account.

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

/* Register Auto Loader */
spl_autoload_register(array('HarvestAPI', 'autoload'));

$api = new HarvestReports();
$api->setUser( "test@test.com" );
$api->setPassword( "test123" );
$api->setAccount( "test" );

$api->setRetryMode( HarvestAPI::RETRY );
$api->setSSL(true);

$result = $api->getActiveProjects();
if( $result->isSuccess() ) {
    foreach( $result->data as $project ) {
        echo $project->name;
    }
}

Get all Inactive Contractor Users

The getInactiveContractors function will return only users that are of type contractor and their status is inactive. In addition you could also get all Contractors getContractors or only the active contractors getActiveContractors.

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

/* Register Auto Loader */
spl_autoload_register(array('HarvestAPI', 'autoload'));

$api = new HarvestReports();
$api->setUser( "test@test.com" );
$api->setPassword( "test123" );
$api->setAccount( "test" );

$api->setRetryMode( HarvestAPI::RETRY );
$api->setSSL(true);

$result = $api->getInactiveContractors();
if( $result->isSuccess() ) {
    foreach( $result->data as $contractor) {
        echo $contractor->get( "first-name" );
        echo $contractor->get( "last-name" );
    }
}

Get a User’s Active Timer

The getUsersActiveTimer function will return the user’s active timer or if no timer is currently active it will return null. In addition you could also get all active timers for all users in your account by using the getActiveTimers function.

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

/* Register Auto Loader */
spl_autoload_register(array('HarvestAPI', 'autoload'));

$api = new HarvestReports();
$api->setUser( "test@test.com" );
$api->setPassword( "test123" );
$api->setAccount( "test" );

$api->setRetryMode( HarvestAPI::RETRY );
$api->setSSL(true);

$result = $api->getUsersActiveTimer( 12345 );
if( $result->isSuccess() ) {
    if( ! is_null( $result->data ) {
        echo $result->get( "started-at" );
    }
}

Comments & Questions

  1. actually, there is a TYPO here

    instead of
    $result = $api->getUserActiveTimer( 12345 );

    needs to be getUsersActiveTimer

    1. Thanks James, I’ll make sure to update accordingly.

  2. not working

    Call to undefined method HarvestReports::getUserActiveTimer()

    i’ve tried in cluding harvestreports.php

Add Your Comment

Leave a Reply to james Cancel