API

You can interact with your tasks from other plugins or from custom scripts by using the methods exposed from the plugin instance.

The ID in each case will be the block reference (block ID) on the task line. You can find all block references for a note with app.metadataCache.getCache().

// Get a task from its block ID
const task = tz.tasks.getTaskById(1)
// Add a scheduled date
task.scheduled = '2026-01-20'
// Update the task in the original note
task.update()
 
// Get an array of all #someday tasks
const somedayTasks = tz.tasks.getTasks('someday')
 
// Add a subtask to an existing task
const parent = tz.tasks.getTaskById(2)
const subtask = await parent.addSubtask('This is the child task text')
subtask.setAs('waiting-on') // Will update the original note
 
// Move a task to a specific note
const task2 = tz.tasks.getTaskById(10)
task2.move('Path/To/Some Note.md')

Dataview examples

List your next actions

Here’s an example of how to list your next actions with Dataview:

```dataviewjs
// Get the list of next actions from Task Zero
const nextActions = tz.tasks.getTasks('next-action')
 
// Output the list as a Dataview task list
dv.taskList(
  dv.pages().file.tasks
    .filter(task => nextActions
      .map(x => tz.tasks.blockPrefix + x.id)
      .includes(task.blockId))
)
```

List of due / overdue tasks

```dataviewjs
// Get the list of due / overdue tasks
const tasks = tz.tasks.getTasks().filter(task => task.isDue)
 
// Output as a Dataview task list
dv.taskList(
  dv.pages().file.tasks
    .filter(task => tasks
      .map(x => tz.tasks.blockPrefix + x.id)
      .includes(task.blockId))
)
```

Show a table of all tasks with a due date

```dataviewjs
dv.table(['Task', 'Note', 'Scheduled'],
  tz.tasks
    .getTasks()
    .filter(task => task.scheduled)
    .map(task => [
      task.text, 
      dv.fileLink(task.path), 
      task.scheduled
    ])
)
```