0

Delete Filter

by
Published Jun 6, 2022

Deletes a filter. [See the docs here](https://developer.todoist.com/sync/v9/#delete-a-filter)

Script todoist Verified

The script

Submitted by hugo697 Bun
Verified 398 days ago
1
import { v9 as Todoist } from 'todoist'
2
import { v4 as uuidv4 } from 'uuid'
3

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

8
interface Response {
9
	full_sync: boolean
10
	sync_status: Sync_status
11
	sync_token: string
12
}
13

14
interface Sync_status {
15
	[key: string]: string
16
}
17

18
export async function main(
19
	resource: Todoist,
20
	filter: {
21
		id: number | string
22
	}
23
) {
24
	const response = await fetch('https://api.todoist.com/sync/v9/sync', {
25
		method: 'POST',
26
		headers: {
27
			Authorization: `Bearer ${resource.Token}`,
28
			'Content-Type': 'application/json'
29
		},
30
		body: JSON.stringify({
31
			commands: JSON.stringify([
32
				{
33
					type: 'filter_delete',
34
					uuid: uuidv4(),
35
					args: { id: filter.id.toString() }
36
				}
37
			])
38
		})
39
	})
40

41
	const data = (await response.json()) as Response
42
	const status = Object.values(data.sync_status)[0]
43
	if (status === 'ok') {
44
		return {
45
			is_deleted: true
46
		}
47
	}
48
}
49