In this Example you will learn how to setup & configure the Harvest api PHP interface library.
- 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.
- 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.
- Set Account & User information
$api = new HarvestAPI(); $api->setUser( "firstname.lastname@example.org" ); $api->setPassword( "password" ); $api->setAccount( "account" );
*The account is the subdomain used to access harvest. For example if you access harvest at http://company123.harvestapp.com/ then account should be set to company123.
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 );
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
- Understanding the Harvest_Result Object – An introduction to the Harvest_Result object and what information is returned to the user.