go-harvest is a Go client library for accessing Harvest API v2
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.NewAPIClient(tc)
service.AccountID = os.Getenv("HARVEST_ACCOUNT_ID")
c, _, err := service.Company.Get(ctx)
if err != nil {
fmt.Print(err)
panic("Exit company")
}
- [ - ] Partially done
- [ x ] Complete
- [ - ] Authentication
- [ x ] Client Contacts
- [ x ] Clients
- [ x ] Company
- [ x ] Invoice Messages
- [ x ] Invoice Payments
- [ x ] Invoices
- [ x ] Invoice Item Categories
- [ x ] Estimate Messages
- [ - ] Estimates
- [ - ] Estimate Item Categories
- [ x ] Expenses
- [ x ] Expense Categories
- [ x ] Tasks
- [ - ] Time Entries
- [ - ] Project User Assignments
- [ - ] Project Task Assignments
- [ - ] Projects
- [ X ] Roles
- [ - ] User Project Assignments
- [ x ] Users
- Unit tests
- Rate limits
- Documentation
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 {
log.Error(err)
return
}
fmt.Println("Company info")
fmt.Println(c.String())
clientList, _, err := service.Client.List(ctx, &harvest.ClientListOptions{})
if err != nil {
log.Error(err)
return
}
fmt.Println("Client list")
fmt.Println(clientList.String())
contactList, _, err := service.Client.ListContacts(ctx, &harvest.ClientContactListOptions{})
if err != nil {
log.Error(err)
return
}
fmt.Println("Contact list")
fmt.Println(contactList.String())
projectList, _, err := service.Project.List(ctx, &harvest.ProjectListOptions{})
if err != nil {
log.Error(err)
return
}
fmt.Println("Project list")
fmt.Println(projectList.String())
taskList, _, err := service.Task.List(ctx, &harvest.TaskListOptions{})
if err != nil {
log.Error(err)
return
}
fmt.Println("Task list")
fmt.Println(taskList.String())
userList, _, err := service.User.List(ctx, &harvest.UserListOptions{})
if err != nil {
log.Error(err)
return
}
fmt.Println("User list")
fmt.Println(userList.String())
estimateList, _, err := service.Estimate.List(ctx, &harvest.EstimateListOptions{})
if err != nil {
log.Error(err)
return
}
fmt.Println("Estimate list")
fmt.Println(estimateList.String())
invoiceList, _, err := service.Invoice.List(ctx, &harvest.InvoiceListOptions{})
if err != nil {
log.Error(err)
return
}
fmt.Println("Invoice list")
fmt.Println(invoiceList.String())
roleList, _, err := service.Role.List(ctx, &harvest.RoleListOptions{})
if err != nil {
log.Error(err)
return
}
fmt.Println("Role list")
fmt.Println(roleList.String())