HaPi – Harvest api PHP interface

PHP Wrapper Library for the Harvest API

Harvest users can use the Harvest API to query and utilize information from their Harvest account in their own applications. Currently there is an open-sourced Harvest Ruby wrapper that can be obtained from github. But as I prefer to utilize PHP, I have created the Harvest api PHP interface (HaPi) library. This Open Source library is licensed under the GNU General Public License v3 license.

The current version of the library is 1.1.0. This release contains support for the full Time Tracking and Extended Rest APIs and requires the user to have cURL support. In addition this version of the library contains the HarvestReports object which can be used to perform additional queries like getActiveProjects and getActiveTimers. Please visit the downloads page to download the latest version of the library.

Comments & Questions

  1. Line 1323 / 1324:

    $url = “expesnses/$expense->id”;
    return $this->performPUT( $url, $obj->toXML() );

    should be:

    $url = “expenses/$expense->id”;
    return $this->performPUT( $url, $expense->toXML() );

    1. Hi Turaj:

      Thanks for reporting the typo. It looks like the current version on GitHub has the fix implimented. https://github.com/mdbitz/HaPi

  2. Hi, are you looking at publishing this library on GitHub so others can contribute to it? Thanks

  3. Great API. Thanks.

    There is a typo on line 2264
    $inovice_id should be $invoice_id

  4. how i set session in harvest api php

  5. I have written as

    setUser( "nida.amin@gmail.com" );
       $api->setPassword( "aaabbb12345" );
       $api->setAccount( "heavenscompany" );
    
       $api->setRetryMode( HarvestAPI::RETRY );
       $api->setSSL(true);
    
       $result = $api->getClients();
       foreach( $result->data as $client ) {
           if( $result->isSuccess() ) {
               echo $client->get( "name" );
               echo $client->details;
           }
      }
    

    Please help me how to get other contact details of the client like email, mobile no’s, office…etc in Harvest API in php?

    1. Hi, Harvest unfortunately doesn’t store contact information at the Client level. Within Harvest they have a single “Address” field that gets returned in the details property of the Client object. If you wanted to you can add the client’s phone numbers and email into this section however you would need to then parse the text for separating the information.

      For example you could specify a token at the beginning of each line (phone) xxx-xxx-xxxx (email) xxx@xxxxx.xxx and do a read of each line to get the individual values returned.

      Also you should switch your if success and foreach statement around as follows

      $result = $api->getClients();
      if( $result->isSuccess() ) {
          foreach( $result->data as $client ) {
              ...
          }
      }
      
  6. We have some additions to the code that we would like to submit. How do we send our updates?

  7. Very nice tools, thank you!

    I just noticed it does not support the “of_user” parameter for createEntry() function / api call.

    1. Andreas:

      I haven’t made updates to the HaPi library in some time. I should have some free time in the next couple of weeks to review and I’ll sync it with the current Harvest functionality.

  8. Found a bug. HarvestAPI.php line 1524:

    $url = “projects/” . $userAssignment->get(“project-id”) . “/user_assignments/” . $userAssignment->get(“user-id”);

    should be:

    $url = “projects/” . $userAssignment->get(“project-id”) . “/user_assignments/” . $userAssignment->get(“id”);

Add Your Comment

Leave a Reply to akh Cancel