godoist

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

README

godoist

A Go client library for the Todoist API v1.

Install

go get github.com/harlequix/godoist

Usage

Basic Usage
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/harlequix/godoist"
)

func main() {
	td := godoist.NewTodoist(os.Getenv("TODOIST_TOKEN"))

	// Fetch all tasks and projects (uses REST API by default)
	if err := td.Sync(); err != nil {
		log.Fatal(err)
	}

	// List projects
	for _, p := range td.Projects.All() {
		fmt.Printf("Project: %s (%s)\n", p.Name, p.ID)
	}

	// List tasks
	for _, t := range td.Tasks.All() {
		fmt.Printf("  [%s] %s (priority: %s)\n", t.ID, t.Content, t.Priority)
	}

	// Create a task
	task, err := td.Tasks.Create("Buy groceries")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Created: %s (%s)\n", task.Content, task.ID)

	// Update a task
	task.Update("content", "Buy groceries and snacks")

	// Add a label
	task.AddLabel("errands")

	// Complete a task
	task.Close()

	// Working with context (metadata stored in comments)
	// Add context to a task
	task.SetContext(map[string]interface{}{
		"source": "email",
		"urgency": "high",
		"tags": []string{"work", "important"},
	})

	// Get context from a task
	context, err := task.GetContext()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Task context: %v\n", context)

	// Update specific fields in context
	task.UpdateContext(map[string]interface{}{
		"urgency": "medium",
	})

	// Delete a specific field from context
	task.DeleteContextField("tags")

	// Delete all context
	task.DeleteContext()

	// Working with comments
	comments, err := task.GetComments()
	if err != nil {
		log.Fatal(err)
	}
	for _, c := range comments {
		fmt.Printf("Comment: %s\n", c.Content)
	}
}
Using Sync API

For better performance, you can use the Todoist Sync API endpoint instead of REST API calls:

config := &godoist.Config{
	Token:      os.Getenv("TODOIST_TOKEN"),
	UseSyncAPI: true,
}
td := godoist.NewTodoistWithConfig(config)

// This will now use /sync endpoint instead of separate REST calls
if err := td.Sync(); err != nil {
	log.Fatal(err)
}
Configuration Options

You can configure the client using a Config struct:

config := &godoist.Config{
	Token:      "your-token",
	ApiURL:     "https://api.todoist.com/api/v1",  // default
	Timeout:    30,                                 // default
	Debug:      false,                              // default
	UseSyncAPI: true,                               // use /sync endpoint (default: false)
}
td := godoist.NewTodoistWithConfig(config)

Configuration can also be loaded from files (YAML/TOML) and environment variables:

config, err := godoist.BuildConfig(
	[]string{"config.yaml", "config.toml"}, // config files
	"TODOIST_",                              // env prefix
	&godoist.Config{UseSyncAPI: true},      // overrides
)
if err != nil {
	log.Fatal(err)
}
td := godoist.NewTodoistWithConfig(config)

License

MIT

Documentation

Index

Constants

View Source
const ContextPrefix = "[CONTEXT]"

Variables

View Source
var (
	APIURL = "https://api.todoist.com/api/v1"
)

Functions

This section is empty.

Types

type Comment added in v0.3.3

type Comment struct {
	ID        string `json:"id"`
	TaskID    string `json:"task_id"`
	Content   string `json:"content"`
	PostedAt  string `json:"posted_at"`
	ProjectID string `json:"project_id"`
}

type Config added in v0.0.1

type Config struct {
	Token      string `koanf:"token"`
	ApiURL     string `koanf:"api_url"`
	Timeout    int    `koanf:"timeout"`
	Debug      bool   `koanf:"debug"`
	UseSyncAPI bool   `koanf:"use_sync_api"`
}

func BuildConfig added in v0.0.1

func BuildConfig(files []string, envPrefix string, external interface{}) (*Config, error)

func (Config) Merge added in v0.0.1

func (config Config) Merge(other *Config)

type Deadline

type Deadline struct {
	Date       string    `json:"date"`
	Lang       string    `json:"lang"`
	ParsedDate time.Time `json:"-"`
}

func (*Deadline) UnmarshalJSON

func (d *Deadline) UnmarshalJSON(data []byte) error

type Due

type Due struct {
	Date        string    `json:"date"`
	Lang        string    `json:"lang"`
	String      string    `json:"string"`
	Timezone    string    `json:"timezone"`
	IsRecurring bool      `json:"is_recurring"`
	ParsedDate  time.Time `json:"-"`
}

func (*Due) UnmarshalJSON

func (d *Due) UnmarshalJSON(data []byte) error

type Duration added in v0.3.0

type Duration struct {
	Amount int    `json:"amount"`
	Unit   string `json:"unit"` // "minute" or "day"
}

type Manager

type Manager struct {
	Tasks    *TaskManager
	Projects *ProjectManager
}

type PRIORITY_LEVEL

type PRIORITY_LEVEL int
const (
	HIGH     PRIORITY_LEVEL = 4
	MEDIUM   PRIORITY_LEVEL = 3
	LOW      PRIORITY_LEVEL = 2
	VERY_LOW PRIORITY_LEVEL = 1
)

func (PRIORITY_LEVEL) String

func (p PRIORITY_LEVEL) String() string

type Project

type Project struct {
	ID           string          `json:"id"`
	Name         string          `json:"name"`
	Description  string          `json:"description"`
	Color        string          `json:"color"`
	ParentID     string          `json:"parent_id"`
	ChildOrder   int             `json:"child_order"`
	IsShared     bool            `json:"is_shared"`
	InboxProject bool            `json:"inbox_project"`
	IsFavorite   bool            `json:"is_favorite"`
	IsArchived   bool            `json:"is_archived"`
	IsCollapsed  bool            `json:"is_collapsed"`
	ViewStyle    string          `json:"view_style"`
	DefaultOrder int             `json:"default_order"`
	CreatedAt    string          `json:"created_at"`
	UpdatedAt    string          `json:"updated_at"`
	URL          string          `json:"url"`
	Manager      *ProjectManager `json:"-"`
}

func (*Project) GetChildren

func (p *Project) GetChildren() []*Project

func (*Project) GetTasks

func (p *Project) GetTasks() []*Task

func (*Project) Update added in v0.0.1

func (p *Project) Update(key string, value interface{}) error

type ProjectManager

type ProjectManager struct {
	Manager *Manager
	// contains filtered or unexported fields
}

func NewProjectManager

func NewProjectManager(api *TodoistAPI) *ProjectManager

func (*ProjectManager) AddProject

func (p *ProjectManager) AddProject(project Project)

func (*ProjectManager) All

func (p *ProjectManager) All() []*Project

func (*ProjectManager) Get

func (p *ProjectManager) Get(id string) *Project

func (*ProjectManager) GetByName

func (p *ProjectManager) GetByName(name string) []*Project

func (*ProjectManager) Update

func (p *ProjectManager) Update(projects []Project)

type SyncResponse added in v0.3.3

type SyncResponse struct {
	Items    []Task    `json:"items"`
	Projects []Project `json:"projects"`
}

type Task

type Task struct {
	ID          string         `json:"id"`
	Content     string         `json:"content"`
	Description string         `json:"description"`
	ProjectID   string         `json:"project_id"`
	SectionID   string         `json:"section_id"`
	ChildOrder  int            `json:"child_order"`
	Priority    PRIORITY_LEVEL `json:"priority"`
	Deadline    *Deadline      `json:"deadline"`
	Due         *Due           `json:"due"`
	Duration    *Duration      `json:"duration"`
	ParentID    string         `json:"parent_id"`
	Labels      []string       `json:"labels"`
	Checked     bool           `json:"checked"`
	AddedAt     string         `json:"added_at"`
	UpdatedAt   string         `json:"updated_at"`
	CompletedAt string         `json:"completed_at"`
	NoteCount   int            `json:"note_count"`
	DayOrder    int            `json:"day_order"`
	IsCollapsed bool           `json:"is_collapsed"`
	URL         string         `json:"url"`
	// contains filtered or unexported fields
}

func (*Task) AddLabel

func (t *Task) AddLabel(label string)

func (*Task) Close added in v0.2.0

func (t *Task) Close() error

func (*Task) DeleteContext added in v0.3.3

func (t *Task) DeleteContext() error

DeleteContext removes the context comment entirely

func (*Task) DeleteContextField added in v0.3.3

func (t *Task) DeleteContextField(key string) error

DeleteContextField removes a specific field from the context

func (*Task) GetChildren

func (t *Task) GetChildren() []*Task

func (*Task) GetComments added in v0.3.3

func (t *Task) GetComments() ([]Comment, error)

GetComments retrieves all comments for a task

func (*Task) GetContext added in v0.3.3

func (t *Task) GetContext() (map[string]interface{}, error)

GetContext retrieves the context data for a task

func (*Task) RemoveLabel

func (t *Task) RemoveLabel(label string) error

func (*Task) Reopen added in v0.3.0

func (t *Task) Reopen() error

func (*Task) SetContext added in v0.3.3

func (t *Task) SetContext(contextData map[string]interface{}) error

SetContext sets or updates the context data for a task

func (*Task) String

func (t *Task) String() string

func (*Task) UnmarshalJSON

func (t *Task) UnmarshalJSON(data []byte) error

func (*Task) Update

func (t *Task) Update(key string, value interface{}) error

func (*Task) UpdateContext added in v0.3.3

func (t *Task) UpdateContext(updates map[string]interface{}) error

UpdateContext updates specific fields in the context without replacing everything

type TaskManager

type TaskManager struct {
	Manager *Manager
	// contains filtered or unexported fields
}

func NewTaskManager

func NewTaskManager(api *TodoistAPI) *TaskManager

func (*TaskManager) AddTask

func (t *TaskManager) AddTask(task Task) error

func (*TaskManager) All

func (t *TaskManager) All() []*Task

func (*TaskManager) Create

func (t *TaskManager) Create(content string) (*Task, error)

func (*TaskManager) Get

func (t *TaskManager) Get(id string) *Task

func (*TaskManager) GetByName

func (t *TaskManager) GetByName(name string) []*Task

func (*TaskManager) Len

func (t *TaskManager) Len() int

func (*TaskManager) String

func (t *TaskManager) String() string

func (*TaskManager) Update

func (t *TaskManager) Update(tasks []Task)

func (*TaskManager) UpdateTask

func (t *TaskManager) UpdateTask(task Task)

type Todoist

type Todoist struct {
	Token string

	API        *TodoistAPI
	Tasks      TaskManager
	Projects   ProjectManager
	UseSyncAPI bool
	// contains filtered or unexported fields
}

func NewTodoist

func NewTodoist(token string) *Todoist

NewTodoist creates a new Todoist client

func NewTodoistWithConfig added in v0.3.3

func NewTodoistWithConfig(config *Config) *Todoist

NewTodoistWithConfig creates a new Todoist client with configuration

func (*Todoist) Commit added in v0.2.0

func (t *Todoist) Commit() error

Commit is a no-op kept for backwards compatibility. The API v1 executes operations immediately; there is nothing to commit.

func (*Todoist) Sync

func (t *Todoist) Sync() error

type TodoistAPI

type TodoistAPI struct {
	Token string
	// contains filtered or unexported fields
}

func NewDispatcher

func NewDispatcher(token string) *TodoistAPI

NewDispatcher creates a new Todoist API client

func (*TodoistAPI) CloseTask added in v0.2.0

func (t *TodoistAPI) CloseTask(id string) error

func (*TodoistAPI) CreateComment added in v0.3.3

func (api *TodoistAPI) CreateComment(taskID, content string) (*Comment, error)

CreateComment creates a comment for a task

func (*TodoistAPI) CreateProject added in v0.2.0

func (t *TodoistAPI) CreateProject(fields map[string]interface{}) (*Project, error)

func (*TodoistAPI) CreateTask added in v0.2.0

func (t *TodoistAPI) CreateTask(fields map[string]interface{}) (*Task, error)

func (*TodoistAPI) DeleteComment added in v0.3.3

func (api *TodoistAPI) DeleteComment(commentID string) error

DeleteComment deletes a comment by its ID

func (*TodoistAPI) DeleteTask added in v0.5.0

func (t *TodoistAPI) DeleteTask(id string) error

DeleteTask deletes a task by ID.

func (*TodoistAPI) GetComments added in v0.3.3

func (api *TodoistAPI) GetComments(taskID string) ([]Comment, error)

GetComments retrieves all comments for a task

func (*TodoistAPI) GetProjects added in v0.2.0

func (t *TodoistAPI) GetProjects() ([]Project, error)

func (*TodoistAPI) GetTasks added in v0.2.0

func (t *TodoistAPI) GetTasks() ([]Task, error)

func (*TodoistAPI) MoveTask added in v0.5.0

func (t *TodoistAPI) MoveTask(taskID, projectID, parentID string) error

MoveTask moves a task to a different project and/or parent.

func (*TodoistAPI) ReopenTask added in v0.3.0

func (t *TodoistAPI) ReopenTask(id string) error

func (*TodoistAPI) SyncResources added in v0.3.3

func (t *TodoistAPI) SyncResources(resourceTypes []string) (*SyncResponse, error)

SyncResources fetches specified resources using the sync endpoint

func (*TodoistAPI) UpdateComment added in v0.3.3

func (api *TodoistAPI) UpdateComment(commentID, content string) error

UpdateComment updates a comment by its ID

func (*TodoistAPI) UpdateProject added in v0.2.0

func (t *TodoistAPI) UpdateProject(id string, fields map[string]interface{}) error

func (*TodoistAPI) UpdateTask added in v0.2.0

func (t *TodoistAPI) UpdateTask(id string, fields map[string]interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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