clockify

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 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) CreateTag added in v0.10.0

func (c *Client) CreateTag(ctx context.Context, workspaceID string, req CreateTagRequest) (*Tag, error)

CreateTag creates a workspace tag (POST, 201).

func (*Client) CreateTask added in v0.10.0

func (c *Client) CreateTask(ctx context.Context, workspaceID, projectID string, req CreateTaskRequest) (*Task, error)

CreateTask creates a task on a project (POST, 201).

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) DeleteTag added in v0.10.0

func (c *Client) DeleteTag(ctx context.Context, workspaceID, tagID string) error

DeleteTag permanently removes a tag (DELETE, 204 No Content).

func (*Client) DeleteTask added in v0.10.0

func (c *Client) DeleteTask(ctx context.Context, workspaceID, projectID, taskID string) error

DeleteTask permanently removes a task from a project (DELETE, 204).

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) DuplicateTimeEntry added in v0.9.0

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

DuplicateTimeEntry duplicates an existing entry (POST .../duplicate, no body). Returns the newly created entry (201).

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) GetTag added in v0.10.0

func (c *Client) GetTag(ctx context.Context, workspaceID, tagID string) (*Tag, error)

GetTag fetches a single tag by ID.

func (*Client) GetTags added in v0.10.0

func (c *Client) GetTags(ctx context.Context, workspaceID string, params TagListParams) ([]Tag, error)

GetTags lists workspace tags, following pagination (up to 50 pages as a safety bound).

func (*Client) GetTask added in v0.10.0

func (c *Client) GetTask(ctx context.Context, workspaceID, projectID, taskID string) (*Task, error)

GetTask fetches a single task by ID.

func (*Client) GetTasks added in v0.10.0

func (c *Client) GetTasks(ctx context.Context, workspaceID, projectID string, params TaskListParams) ([]Task, error)

GetTasks lists tasks on a project, 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) UpdateTag added in v0.10.0

func (c *Client) UpdateTag(ctx context.Context, workspaceID, tagID string, req UpdateTagRequest) (*Tag, error)

UpdateTag renames or archives a tag (PUT).

func (*Client) UpdateTask added in v0.10.0

func (c *Client) UpdateTask(ctx context.Context, workspaceID, projectID, taskID string, req UpdateTaskRequest) (*Task, error)

UpdateTask edits a task on a project (PUT). Name is required by the API.

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 CreateTagRequest added in v0.10.0

type CreateTagRequest struct {
	Name string `json:"name"`
}

CreateTagRequest is the body for POST /v1/workspaces/{workspaceId}/tags.

type CreateTaskRequest added in v0.10.0

type CreateTaskRequest struct {
	Name     string     `json:"name"`
	Status   TaskStatus `json:"status,omitempty"`
	Estimate string     `json:"estimate,omitempty"` // ISO-8601, e.g. "PT1H30M"
}

CreateTaskRequest is the body for POST /v1/workspaces/{workspaceId}/projects/{projectId}/tasks. Name is required by the API.

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 Tag added in v0.10.0

type Tag struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Archived    bool   `json:"archived"`
	WorkspaceID string `json:"workspaceId"`
}

Tag is a workspace tag returned by GET /v1/workspaces/{workspaceId}/tags.

type TagBrief

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

TagBrief is a hydrated tag embedded in a time entry.

type TagListParams added in v0.10.0

type TagListParams struct {
	Name             string // server-side substring filter; "" = no filter
	StrictNameSearch bool   // make Name an exact-match filter
	Archived         *bool  // nil = both; true = archived only
	PageSize         int    // per page; default 100
}

TagListParams are query options for GetTags.

type Task added in v0.10.0

type Task struct {
	ID        string     `json:"id"`
	Name      string     `json:"name"`
	ProjectID string     `json:"projectId"`
	Status    TaskStatus `json:"status"`
	Estimate  string     `json:"estimate,omitempty"` // ISO-8601 duration, e.g. "PT1H30M"
	Billable  bool       `json:"billable"`
	Duration  string     `json:"duration,omitempty"` // tracked time so far, e.g. "PT1H30M"
}

Task is a project task returned by GET /v1/workspaces/{workspaceId}/projects/{projectId}/tasks.

type TaskBrief

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

TaskBrief is a hydrated task embedded in a time entry.

type TaskListParams added in v0.10.0

type TaskListParams struct {
	Name             string // server-side substring filter; "" = no filter
	StrictNameSearch bool   // make Name an exact-match filter
	IsActive         *bool  // nil = both; true = active only
	PageSize         int    // per page; default 100
}

TaskListParams are query options for GetTasks.

type TaskStatus added in v0.10.0

type TaskStatus string

TaskStatus is the lifecycle state of a project task.

const (
	TaskStatusActive TaskStatus = "ACTIVE"
	TaskStatusDone   TaskStatus = "DONE"
)

Task status values accepted by the API.

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 UpdateTagRequest added in v0.10.0

type UpdateTagRequest struct {
	Name     *string `json:"name,omitempty"`
	Archived *bool   `json:"archived,omitempty"`
}

UpdateTagRequest is the body for PUT /v1/workspaces/{workspaceId}/tags/{id}. Both fields are optional; omit one to leave it unchanged.

type UpdateTaskRequest added in v0.10.0

type UpdateTaskRequest struct {
	Name     string     `json:"name"`
	Status   TaskStatus `json:"status,omitempty"`
	Estimate string     `json:"estimate,omitempty"`
	Billable *bool      `json:"billable,omitempty"`
}

UpdateTaskRequest is the body for PUT /v1/workspaces/{workspaceId}/projects/{projectId}/tasks/{id}. Name is required by the API.

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. TaskID and TagIDs are pointers so an explicit empty value can clear them (an empty string/slice is otherwise indistinguishable from "omit").

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