clockify

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clockify provides a thin, fully-typed HTTP client for the Clockify REST API (https://docs.clockify.me).

Package clockify provides a thin, fully-typed HTTP client for the Clockify REST API (https://docs.clockify.me).

Index

Constants

View Source
const DefaultBaseURL = "https://api.clockify.me/api/v1"

DefaultBaseURL is the global Clockify API endpoint. Regional workspaces can use a prefixed host instead (e.g. https://euc1.clockify.me/api/v1).

Variables

This section is empty.

Functions

func IsForbidden

func IsForbidden(err error) bool

IsForbidden reports whether err is a 403 (missing workspace permission).

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether err is a 404.

func IsRateLimited

func IsRateLimited(err error) bool

IsRateLimited reports whether err is a 429 (too many requests).

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized reports whether err is a 401 (bad or expired API key).

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to v; handy for optional JSON request fields.

Types

type APIError

type APIError struct {
	StatusCode int
	Method     string
	Path       string
	Message    string
}

APIError is returned for any non-2xx response.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the Clockify REST API using an API key (X-Api-Key header).

func NewClient

func NewClient(baseURL, apiKey string) *Client

NewClient returns a Client for baseURL (or DefaultBaseURL when empty) authenticated with apiKey.

func (*Client) CreateTimeEntry

func (c *Client) CreateTimeEntry(ctx context.Context, workspaceID string, req CreateTimeEntryRequest) (*TimeEntry, error)

CreateTimeEntry creates a time entry. Omit End to start a running timer (Clockify then stops any previously running timer). Timestamps are normalized to UTC before sending.

func (*Client) DeleteTimeEntry

func (c *Client) DeleteTimeEntry(ctx context.Context, workspaceID, entryID string) error

DeleteTimeEntry permanently removes a time entry (DELETE, 204 No Content).

func (*Client) GetInProgress

func (c *Client) GetInProgress(ctx context.Context, workspaceID string) ([]TimeEntry, error)

GetInProgress returns the currently running timers on a workspace.

func (*Client) GetProjects

func (c *Client) GetProjects(ctx context.Context, workspaceID string, params ProjectListParams) ([]Project, error)

GetProjects lists projects on a workspace, following pagination (up to 50 pages as a safety bound).

func (*Client) GetTimeEntries

func (c *Client) GetTimeEntries(ctx context.Context, workspaceID, userID string, params TimeEntryListParams) ([]TimeEntry, error)

GetTimeEntries lists a user's time entries (newest first). When params.Start or params.End are set, only entries whose *start time* falls inside the window are returned (Clockify filters on entry start, not on overlap).

func (*Client) GetTimeEntry

func (c *Client) GetTimeEntry(ctx context.Context, workspaceID, entryID string) (*TimeEntry, error)

GetTimeEntry fetches a single time entry by ID.

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context) (*User, error)

GetUser returns the authenticated user (GET /user).

func (*Client) GetWorkspaces

func (c *Client) GetWorkspaces(ctx context.Context) ([]Workspace, error)

GetWorkspaces lists the workspaces the authenticated user belongs to.

func (*Client) StopTimer

func (c *Client) StopTimer(ctx context.Context, workspaceID, userID string, end time.Time) (*TimeEntry, error)

StopTimer stops the user's running timer. The PATCH endpoint requires only an end timestamp in the body (the path carries workspace and user IDs).

func (*Client) UpdateTimeEntry

func (c *Client) UpdateTimeEntry(ctx context.Context, workspaceID, entryID string, req UpdateTimeEntryRequest) (*TimeEntry, error)

UpdateTimeEntry edits an existing entry (PUT — note PATCH is reserved for stopping a running timer). Start is required by the API. Timestamps are normalized to UTC before sending.

type CreateTimeEntryRequest

type CreateTimeEntryRequest struct {
	Description string     `json:"description,omitempty"`
	Start       *time.Time `json:"start,omitempty"`
	End         *time.Time `json:"end,omitempty"`
	ProjectID   string     `json:"projectId,omitempty"`
	Billable    *bool      `json:"billable,omitempty"`
	TaskID      string     `json:"taskId,omitempty"`
	TagIDs      []string   `json:"tagIds,omitempty"`
}

CreateTimeEntryRequest is the body for POST /v1/workspaces/{workspaceId}/time-entries. Omit End to start a running timer.

type Project

type Project struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Archived bool   `json:"archived"`
	Billable bool   `json:"billable"`
	Color    string `json:"color"`
}

Project is a workspace project returned by GET /v1/workspaces/{id}/projects.

type ProjectBrief

type ProjectBrief struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	ClientID   string `json:"clientId"`
	ClientName string `json:"clientName"`
	Color      string `json:"color"`
}

ProjectBrief is the hydrated project snapshot embedded in time entries when a list request sets hydrated=true.

type ProjectListParams added in v0.6.0

type ProjectListParams struct {
	Name string // server-side substring filter on the project name; "" = no filter
	// StrictNameSearch makes Name an exact-match filter (ignored without Name).
	StrictNameSearch bool
	// Archived, when set to true, returns only archived projects. There is no
	// server-side "active only" filter: leave it nil (both are returned) and
	// drop archived entries client-side if you need active ones.
	Archived *bool
	PageSize int // per page; default 100
}

ProjectListParams are query options for GetProjects.

type StopTimeEntryRequest

type StopTimeEntryRequest struct {
	End time.Time `json:"end"`
}

StopTimeEntryRequest is the body for PATCH /v1/workspaces/{workspaceId}/user/{userId}/time-entries (stop the running timer). End is the only required field.

type TagBrief

type TagBrief struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

TagBrief is a hydrated tag embedded in a time entry.

type TaskBrief

type TaskBrief struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

TaskBrief is a hydrated task embedded in a time entry.

type TimeEntry

type TimeEntry struct {
	ID           string        `json:"id"`
	Description  string        `json:"description"`
	Billable     bool          `json:"billable"`
	ProjectID    string        `json:"projectId"`
	TaskID       string        `json:"taskId"`
	TagIDs       []string      `json:"tagIds"`
	UserID       string        `json:"userId"`
	WorkspaceID  string        `json:"workspaceId"`
	Type         string        `json:"type"`
	IsLocked     bool          `json:"isLocked"`
	TimeInterval *TimeInterval `json:"timeInterval"`

	// Populated when the request sets hydrated=true.
	Project *ProjectBrief `json:"project"`
	Task    *TaskBrief    `json:"task"`
	Tags    []TagBrief    `json:"tags"`
}

TimeEntry is a single tracked entry. One struct covers both plain and hydrated responses: hydrated-only fields (Project, Task, Tags) are simply absent otherwise, and TimeEntryInfoDto omits the flat ProjectID/TagIDs.

func (*TimeEntry) EffectiveProjectID

func (t *TimeEntry) EffectiveProjectID() string

EffectiveProjectID returns the project ID from either the flat or the hydrated representation.

func (*TimeEntry) IsRunning

func (t *TimeEntry) IsRunning() bool

IsRunning reports whether the entry has no end time yet.

type TimeEntryListParams

type TimeEntryListParams struct {
	Page     int        // 1-indexed; omitted from the query when <= 0
	PageSize int        // omitted from the query when <= 0
	Hydrated bool       // embed project/task/tag objects instead of bare IDs
	Start    *time.Time // only entries starting at/after this time (UTC on the wire)
	End      *time.Time // only entries starting at/before this time (UTC on the wire)
}

TimeEntryListParams are query options for GetTimeEntries.

type TimeInterval

type TimeInterval struct {
	Start    *time.Time `json:"start"`
	End      *time.Time `json:"end"`
	Duration string     `json:"duration"` // ISO-8601, e.g. "PT1H30M"
}

TimeInterval holds the start/end/duration of a time entry. End is nil while a timer is still running.

type UpdateTimeEntryRequest

type UpdateTimeEntryRequest struct {
	Start       *time.Time `json:"start"`
	Description string     `json:"description,omitempty"`
	End         *time.Time `json:"end,omitempty"`
	ProjectID   string     `json:"projectId,omitempty"`
	Billable    *bool      `json:"billable,omitempty"`
	TaskID      string     `json:"taskId,omitempty"`
	TagIDs      []string   `json:"tagIds,omitempty"`
}

UpdateTimeEntryRequest is the body for PUT /v1/workspaces/{workspaceId}/time-entries/{id}. Start is required by the API; omit optional fields to leave them unchanged.

type User

type User struct {
	ID               string `json:"id"`
	Name             string `json:"name"`
	Email            string `json:"email"`
	ActiveWorkspace  string `json:"activeWorkspace"`
	DefaultWorkspace string `json:"defaultWorkspace"`
}

User is the authenticated account returned by GET /v1/user.

type Workspace

type Workspace struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Workspace is a Clockify workspace returned by GET /v1/workspaces.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL