Go library to use the V2 API of Harvest
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Bert Van Hauwaert 0790972fef
Merge pull request #12 from becoded/github-templates
Add github templates
2019-10-09 00:59:06 +02:00
.github/ISSUE_TEMPLATE Add github templates 2019-10-09 00:58:47 +02:00
harvest format code user project assignment 2019-10-09 00:38:32 +02:00
.gitignore Initial commit 2017-12-29 00:05:04 +01:00
.travis.yml remove integration test 2019-10-09 00:36:09 +02:00
CONTRIBUTING.md Add travis and contributing file 2019-10-09 00:17:55 +02:00
go.mod Add module files 2019-10-09 00:31:21 +02:00
go.sum Add module files 2019-10-09 00:31:21 +02:00
LICENSE Add extra services + License + Readme 2018-02-05 23:44:57 +01:00
README.md Add report 2019-10-09 00:28:42 +02:00

go-harvest

GoDoc Build Status Test Coverage CII Best Practices Go Report Card

go-harvest is a Go client library for accessing Harvest API v2

Usage

import "github.com/becoded/go-harvest/harvest"

Construct a new Harvest client, then use the various services on the client to access different parts of the Harvest API. For example:

ctx := context.Background()
ts := oauth2.StaticTokenSource(
	&oauth2.Token{
        AccessToken: os.Getenv("HARVEST_ACCESS_TOKEN"),
    },
)
tc := oauth2.NewClient(ctx, ts)
service := harvest.NewHarvestClient(tc)
service.AccountId = os.Getenv("HARVEST_ACCOUNT_ID")

c, _, err := service.Company.Get(ctx)
if err != nil {
    fmt.Print(err)
    panic("Exit company")
}

API Introduction

Legend

  • [ - ] Partially done
  • [ x ] Complete

Authentication

Clients API

Company Settings

Invoices API

Estimates API

Expenses API

Tasks API

Timesheets API

Projects API

Roles API

Users API

Todo

  • Unit tests
  • Rate limits
  • Documentation

Examples

Create client

ctx := context.Background()
ts := oauth2.StaticTokenSource(
	&oauth2.Token{
        AccessToken: os.Getenv("HARVEST_ACCESS_TOKEN"),
    },
)
tc := oauth2.NewClient(ctx, ts)

Create service

service := harvest.NewHarvestClient(tc)
service.AccountId = os.Getenv("HARVEST_ACCOUNT_ID")

Get organisation

c, _, err := service.Company.Get(ctx)
if err != nil {
    log.Error(err)
    return
}

fmt.Println("Company info")
fmt.Println(c.String())

Get clients

clientList, _, err := service.Client.List(ctx, &harvest.ClientListOptions{})
if err != nil {
    log.Error(err)
    return
}

fmt.Println("Client list")
fmt.Println(clientList.String())

Get contacts

contactList, _, err := service.Client.ListContacts(ctx, &harvest.ClientContactListOptions{})
if err != nil {
    log.Error(err)
    return
}

fmt.Println("Contact list")
fmt.Println(contactList.String())

Get projects

projectList, _, err := service.Project.List(ctx, &harvest.ProjectListOptions{})
if err != nil {
    log.Error(err)
    return
}

fmt.Println("Project list")
fmt.Println(projectList.String())

Get tasks

taskList, _, err := service.Task.List(ctx, &harvest.TaskListOptions{})
if err != nil {
    log.Error(err)
    return
}

fmt.Println("Task list")
fmt.Println(taskList.String())

Get users

userList, _, err := service.User.List(ctx, &harvest.UserListOptions{})
if err != nil {
    log.Error(err)
    return
}

fmt.Println("User list")
fmt.Println(userList.String())

Get estimates

estimateList, _, err := service.Estimate.List(ctx, &harvest.EstimateListOptions{})
if err != nil {
    log.Error(err)
    return
}

fmt.Println("Estimate list")
fmt.Println(estimateList.String())

Get invoices

invoiceList, _, err := service.Invoice.List(ctx, &harvest.InvoiceListOptions{})
if err != nil {
    log.Error(err)
    return
}

fmt.Println("Invoice list")
fmt.Println(invoiceList.String())

Get roles

roleList, _, err := service.Role.List(ctx, &harvest.RoleListOptions{})
if err != nil {
    log.Error(err)
    return
}

fmt.Println("Role list")
fmt.Println(roleList.String())