Understanding the Harvest_Result Object

All queries made to the Harvest API through the Harvest api PHP interface library returns a Harvest_Result object. To make full use of the data returned it is important to understand what information is returned to you in addition to the requested data.

The Harvest_Result Object

The Harvest_Result object is responsible for containing all the information returned from the server including the response code, header information, and any data returned by the api.

  • code – contains the server response code notifying you if the request was successful or if there was an error. To make it easier on the user the Harvest_Result class contains an isSuccess method to test if the request was successful.
    echo $result->code; // $result->get( "code" );
    if( $result->isSuccess() ) {
  • data – contains the information returned by the server. Depending on the request made to the server it will return either the object requested, an array of objects, or the id of the newly created object.
    $entry = $result->data; // $result->get( "data" );
  • header – is an array containing the header entries from the server response. As the Harvest API utilizes the hint and Retry-After headers I thought some users may find the other information useful. Therefore the header property is populated in each Harvest_Result object and can be accessed simply by specifying the desired header property.
    $entry->hint; // $result->get( "hint" );
    $entry->Location;  // $result->get( "Location" );

One quick thing to notice is that in the library the get and set methods of PHP are used so that you can call a property directly without having to define getHint(), getData(), and etc. Instead you can access a property by either it’s name directly:


or if you prefer you can use the get() method and pass the name of the desired property.

$result->get( "data" );

Comments & Questions

  1. how we can get the number of hours logged by employees in a one day ??

Add Your Comment