A Java client for the Harvest v2 REST api
Clone or download
mnembrini Finish v1.1.1
* release/1.1.1:
  bump to 1.1.1, generate docs
Latest commit 48b479e Apr 11, 2018

README.md

A Harvest Java Client

CircleCI Download codecov Known Vulnerabilities

harvest-client is a Java client for the Harvest REST API (https://help.getharvest.com/api-v2/)

Javadoc

Introduction

With harvest-client you can use the Harvest v2 API with a nice Java interface:

// Load configuration from application.conf in src/main/resources of your application
Harvest harvest = new Harvest();
// list all users
List<User> users = harvest.users().list();

for (User user : users) {
    log.debug("Found user: {}", user);
}
// create new user
User userInfo = ImmutableUser.builder()
                .firstName("first")
                .lastName("last")
                .email("test@example.com")
                .build();

User newUser = harvest.users().create(userInfo);

Have a look in the test folders for examples. Each API endpoint has a Create, List and Update test class.

Download

Download

Gradle

compile 'ch.aaap:harvest-client:$version'

Maven

<dependency>
  <groupId>ch.aaap</groupId>
  <artifactId>harvest-client</artifactId>
  <version>$version</version>
</dependency>

Getting started with Development

Prerequisites

  • Java 8 (or higher)
  • Gradle

Run the build end tests

  • Clone or fork this repository
  • Get a personal access token from Harvest
    • Attention: unit tests assume admin access. Don't run them against a production account!
  • Configuring your Harvest account id and authentication token:
    • You will need 2 Harvest accounts with admin access (it's a limitation of the current Harvest API)
    • Either copy reference.conf to src/test/resources/admin{1,2}.conf and insert your credentials
    • Or set the following environment properties:
        $ export HARVEST_ACCOUNT_ID_ADMIN1=YOUR_ACCT_ID_1
        $ export HARVEST_AUTH_TOKEN_ADMIN1=YOUR_AUTH_TOKEN_1
        $ export HARVEST_ACCOUNT_ID_ADMIN2=YOUR_ACCT_ID_2
        $ export HARVEST_AUTH_TOKEN_ADMIN2=YOUR_AUTH_TOKEN_2
  • Run gradle build in the root directory of the repository

Debugging

You can see the actual HTTP request and response by setting the log level for ch.aaap.harvestclient.core.Harvest.http to TRACE

Log4j2

<Logger name="ch.aaap.harvestclient.core.Harvest.http" level="trace" additivity="false">
    <AppenderRef ref="Console"/>
</Logger>

Found an Harvest Bug?

Check out TestSetupUtil.prepareForHarvestBugReport() to setup your logs before sending them to Harvest.

Contributing

We welcome contributions in the form of pull requests or bug reports! Please read Developers before submitting a pull request. If you plan a big change, please open an issue first so you can get early feedback on your design.