Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.
/ go-harvest Public archive
forked from becoded/go-harvest

Harvest API V2 Documentation

License

Notifications You must be signed in to change notification settings

kastelo-labs/go-harvest

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-harvest

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")
}

Legend

  • [ - ] Partially done
  • [ x ] Complete

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())

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%