modulepackage
0.11.0
Repository: https://github.com/koki-develop/todoist-go.git
Documentation: pkg.go.dev
# README
todoist-go
This is an unofficial Go client library for accessing the Todoist REST API.
Contents
Installation
go get github.com/koki-develop/todoist-go
Import
import "github.com/koki-develop/todoist-go"
Example
Get all projects
package main
import (
"fmt"
"github.com/koki-develop/todoist-go"
)
func main() {
client := todoist.New("TODOIST_API_TOKEN")
projects, err := client.GetProjects()
if err != nil {
fmt.Printf("%s\n", err)
return
}
for _, project := range projects {
fmt.Printf("ID: %d, Name: %s\n", project.ID, project.Name)
// ID: 1234567890, Name: Inbox
// ID: 2345678901, Name: Shopping List
// ...
}
}
Create a new task
package main
import (
"fmt"
"github.com/koki-develop/todoist-go"
)
func main() {
cl := todoist.New("TODOIST_API_TOKEN")
task, err := cl.CreateTask("task content")
if err != nil {
fmt.Printf("%s\n", err)
}
fmt.Printf("ID: %d, Content: %s\n", task.ID, task.Content)
// ID: 3456789012, Content: task content
}
With optional parameters:
package main
import (
"fmt"
"github.com/koki-develop/todoist-go"
)
func main() {
cl := todoist.New("TODOIST_API_TOKEN")
task, err := cl.CreateTaskWithOptions("task content", &todoist.CreateTaskOptions{
// Helper functions can be used to specify optional parameters.
ProjectID: todoist.Int(4567890123),
SectionID: todoist.Int(5678901234),
DueString: todoist.String("every 3 months"),
})
if err != nil {
fmt.Printf("%s\n", err)
}
fmt.Printf("ID: %d, Content: %s\n", task.ID, task.Content)
// ID: 6789012345, Content: task content
}
Handling Errors
todoist-go returns a RequestError
with status code and body when an error response is returned from the Todoist REST API.
package main
import (
"fmt"
"io"
"github.com/koki-develop/todoist-go"
)
func main() {
cl := todoist.New("TODOIST_API_TOKEN")
_, err := cl.GetTask(0)
if reqerr, ok := err.(todoist.RequestError); ok {
// The status code of error response can be retrieved from the StatusCode property.
fmt.Printf("%#v\n", reqerr.StatusCode)
// => 400
// The body of the error response can be retrieved from the Body property as io.Reader.
b, _ := io.ReadAll(reqerr.Body)
fmt.Printf("%#v\n", string(b))
// => "task_id is invalid"
}
}
Documentation
For more information, see todoist-go.
LICENSE
# Structs
No description provided by the author
Client for Todoist REST API.
Options for closing a task.
No description provided by the author
Options for creating attachment.
Options for creating a label.
Options for creating a comment for a project.
Options for creating a project.
Options for creating a section.
Options for creating a comment for a task.
Options for creating a task.
Options for deleting a comment.
Options for deleting a label.
Options for deleting a project.
Options for deleting a section.
Options for deleting a task.
No description provided by the author
Options for getting a sections.
Options for getting a tasks.
No description provided by the author
No description provided by the author
Options for reopening a task.
No description provided by the author
No description provided by the author
No description provided by the author
Options for updating a comment.
Options for updating a label.
Options for updating a project.
Options for updating a section.
Options for updating a task.
No description provided by the author