0
List Filters
One script reply has been approved by the moderators Verified

Returns a list of all filters. See the docs here

Created by danielkelbelle11 1115 days ago Viewed 16750 times
0
Submitted by hugo697 Bun
Verified 414 days ago
1
type Todoist = {
2
	Token: string
3
}
4

5
interface Response {
6
	filters: FiltersItem[]
7
}
8
interface FiltersItem {
9
	color: string
10
	id: string
11
	is_deleted: boolean
12
	is_favorite: boolean
13
	item_order: number
14
	name: string
15
	query: string
16
}
17

18
export async function main(resource: Todoist) {
19
	const response = await fetch('https://api.todoist.com/sync/v9/sync', {
20
		method: 'POST',
21
		headers: {
22
			Authorization: `Bearer ${resource.Token}`,
23
			'Content-Type': 'application/x-www-form-urlencoded'
24
		},
25
		body: new URLSearchParams({
26
			sync_token: '*',
27
			resource_types: '["filters"]'
28
		})
29
	})
30

31
	if (!response.ok) {
32
		throw new Error(`HTTP error! status: ${response.status}`)
33
	}
34
	const data = (await response.json()) as Response
35
	return data.filters
36
}
37