0

Find Task

by
Published Jun 6, 2022

Finds a task by name. [See Docs](https://developer.todoist.com/rest/v2/#get-active-tasks) Optionally, create one if none are found. [See Docs](https://developer.todoist.com/rest/v2/#create-a-new-task)

Script todoist Verified

The script

Submitted by hugo697 Bun
Verified 398 days ago
1
import { TodoistApi } from '@doist/todoist-api-typescript'
2
import { v9 as Todoist } from 'todoist'
3

4
type Todoist = {
5
	Token: string
6
}
7

8
export async function main(resource: Todoist, taskName: string) {
9
	const api = new TodoistApi(resource.Token)
10
	const tasks = await api.getTasks()
11
	let task = tasks.find((t) => t.content === taskName)
12
	if (!task) {
13
		task = await api.addTask({ content: taskName })
14
	}
15
	return task
16
}
17