Skip to content

olsh/todoist-net

Repository files navigation

Todoist.Net

Quality Gate NuGet

A Todoist Sync API client for .NET.

Installation

The library is available as a Nuget package.

Install-Package Todoist.Net

Get started

Creating Todoist client

ITodoistClient client = new TodoistClient("API token");

Quick add

Implementation of the Quick Add Task available in the official clients.

var quickAddTask = new QuickAddTask("Task title @Label1 #Project1 +ExampleUser");
var task = await client.Tasks.QuickAddAsync(quickAddTask);

Simple API calls

// Get all resources (labels, projects, tasks, comments etc.).
var resources = await client.GetResourcesAsync();

// Get only projects and labels.
var projectsAndLabels = await client.GetResourcesAsync(ResourceType.Projects, ResourceType.Labels);

// Get only projects.
var projectsOnly = await client.GetResourcesAsync(ResourceType.Projects);

// Alternatively you can use this API to get projects.
var projects = await client.Projects.GetAsync();

// Add a task with a comment.
var taskId = await client.Tasks.AddAsync(new AddTask("New task"));
await client.Comments.AddToTaskAsync(new Comment("Task description"), taskId);

Transactions (Batching)

Batching: reading and writing of multiple resources can be done in a single HTTP request.

Add a new project, task and note in one request.

// Create a new transaction.
var transaction = client.CreateTransaction();

// These requests are queued and will be executed later.
var projectId = await transaction.Project.AddAsync(new Project("New project"));
var taskId = await transaction.Tasks.AddAsync(new AddTask("New task", projectId));
await transaction.Comments.AddToTaskAsync(new Comment("Task description"), taskId);

// Execute all the requests in the transaction in a single HTTP request.
await transaction.CommitAsync();

Sending null values when updating entities.

When updating entities, Todoist API only updates properties included in the request body, using a PATCH request style. That's why all properties with null values are not included by default, to allow updating without fetching the entity first, since including null properties will update them to null.

However, if you want to intentionally send a null value to the API, you need to use the Unset extension method, for example:

// This code removes a task's due date.
var task = new UpdateTask("TASK_ID");
task.Unset(t => t.DueDate);

await client.Tasks.UpdateAsync(task);

About

A Todoist API client for .NET written in C#

Topics

Resources

License

Stars

Watchers

Forks

Contributors 8

Languages