Basic Setup & Configuration

In this Example you will learn how to setup & configure the Harvest api PHP interface library.

Basic Configurations

  1. Require the HarvestAPI main class
    require_once( dirname(__FILE__) . '/HarvestAPI.php' );

    *Please note that the path may very depending on where your script is in comparison to the Library.

  2. Register the Auto Loader
    spl_autoload_register(array('HarvestAPI', 'autoload') );

    By using the Auto Loader we ensure that classes are loaded only if they are needed.

  3. Set Account & User information
    $api = new HarvestAPI();
    $api->setUser( "" );
    $api->setPassword( "password" );
    $api->setAccount( "account" );

    *The account is the subdomain used to access harvest. For example if you access harvest at then account should be set to company123.

SSL Support

Harvest allows you to enable SSL encryption for your account. If you have it enabled you will need to specify that you need to use the HTTPS protocol in the library by setting the SSL flag to true. This is done by using the setSSL method.

$api->setSSL( true );

Retry Mode

The Harvest API has a built in throttle so that if too many requests are being made against an account it will return HTTP 503 status code instead of the requested data. The HaPi Library has a built in retry mode that if enabled will wait the designated time in the Retry-After response header and resend the request. By default the library will not retry the query and instead will return with a Harvest_Result object who’s status code is 503.

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

Where to go from here

Comments & Questions

  1. While setting up the lib i get this response:

    CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set,

Add Your Comment