harvest-client is a Java client for the Harvest REST API (https://help.getharvest.com/api-v2/)
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("[email protected]")
.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.
compile 'ch.aaap:harvest-client:$version'
<dependency>
<groupId>ch.aaap</groupId>
<artifactId>harvest-client</artifactId>
<version>$version</version>
</dependency>
- Java 8 (or higher)
- Gradle
- 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
You can see the actual HTTP request and response by setting the log level for ch.aaap.harvestclient.core.Harvest.http to TRACE
<Logger name="ch.aaap.harvestclient.core.Harvest.http" level="trace" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
Check out TestSetupUtil.prepareForHarvestBugReport() to setup your logs before sending them to Harvest.
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.