The Toggl API allows developers to interact with Toggl's time tracking service programmatically. It provides endpoints for managing time entries, projects, clients, tags, and user information. With this API, you can automate time tracking, generate detailed reports, and integrate Toggl with other tools and services.
To install the library, use the following command:
go get github.com/go-api-libs/toggl/pkg/togglpackage main
import (
"context"
"os"
"github.com/go-api-libs/toggl/pkg/toggl"
)
func main() {
c, err := toggl.NewClient("myUsername", os.Getenv("TOGGL_PASSWORD"))
if err != nil {
panic(err)
}
ctx := context.Background()
userWithRelated, err := c.GetMe(ctx, &toggl.GetMeParams{WithRelatedData: true})
if err != nil {
panic(err)
}
// Use userWithRelated object
}package main
import (
"context"
"os"
"github.com/go-api-libs/toggl/pkg/toggl"
)
func main() {
c, err := toggl.NewClient("myUsername", os.Getenv("TOGGL_PASSWORD"))
if err != nil {
panic(err)
}
ctx := context.Background()
timeEntry, err := c.CreateTimeEntry(ctx, 2230580, toggl.NewTimeEntry{
CreatedWith: "github.com/go-api-libs/toggl",
Start: mustParseTime("2024-12-15T21:17:59.593648+01:00"),
WorkspaceID: 2230580,
})
if err != nil {
panic(err)
}
// Use timeEntry object
}package main
import (
"context"
"os"
"github.com/go-api-libs/toggl/pkg/toggl"
)
func main() {
c, err := toggl.NewClient("myUsername", os.Getenv("TOGGL_PASSWORD"))
if err != nil {
panic(err)
}
ctx := context.Background()
timeEntry, err := c.GetCurrentTimeEntry(ctx)
if err != nil {
panic(err)
}
// Use timeEntry object
}package main
import (
"context"
"os"
"github.com/go-api-libs/toggl/pkg/toggl"
)
func main() {
c, err := toggl.NewClient("myUsername", os.Getenv("TOGGL_PASSWORD"))
if err != nil {
panic(err)
}
ctx := context.Background()
timeEntry, err := c.StopTimeEntry(ctx, 2230580, 3730303299)
if err != nil {
panic(err)
}
// Use timeEntry object
}package main
import (
"context"
"os"
"github.com/go-api-libs/toggl/pkg/toggl"
)
func main() {
c, err := toggl.NewClient("myUsername", os.Getenv("TOGGL_PASSWORD"))
if err != nil {
panic(err)
}
ctx := context.Background()
timeEntries, err := c.ListTimeEntries(ctx, &toggl.ListTimeEntriesParams{
Before: mustParseTime("2024-12-16T03:25:20+01:00"),
EndDate: mustParseTime("2024-12-16T03:25:20+01:00"),
IncludeSharing: true,
Meta: true,
Since: 1734304527,
StartDate: mustParseTime("2024-12-16T03:25:20+01:00"),
})
if err != nil {
panic(err)
}
// Use timeEntries slice
}package main
import (
"context"
"os"
"github.com/go-api-libs/toggl/pkg/toggl"
)
func main() {
c, err := toggl.NewClient("myUsername", os.Getenv("TOGGL_PASSWORD"))
if err != nil {
panic(err)
}
ctx := context.Background()
simpleOrganization, err := c.CreateOrganization(ctx, toggl.NewOrganization{
Name: "Your Organization",
WorkspaceName: "Your Workspace",
})
if err != nil {
panic(err)
}
// Use simpleOrganization object
}package main
import (
"context"
"os"
"github.com/go-api-libs/toggl/pkg/toggl"
)
func main() {
c, err := toggl.NewClient("myUsername", os.Getenv("TOGGL_PASSWORD"))
if err != nil {
panic(err)
}
ctx := context.Background()
organizations, err := c.ListOrganizations(ctx)
if err != nil {
panic(err)
}
// Use organizations slice
}package main
import (
"context"
"os"
"github.com/go-api-libs/toggl/pkg/toggl"
)
func main() {
c, err := toggl.NewClient("myUsername", os.Getenv("TOGGL_PASSWORD"))
if err != nil {
panic(err)
}
ctx := context.Background()
organization, err := c.GetOrganization(ctx, 9011051)
if err != nil {
panic(err)
}
// Use organization object
}- Go Reference: API documentation.
- API documentation: The official API documentation.
- OpenAPI Specification: The OpenAPI 3.1.0 specification.
Contributions are welcome — please open an issue or a pull request on GitHub.
This project is licensed under the Apache 2.0 License.