0

Task create

by
Published Nov 5, 2024

Create a task in a project

Script taskade Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Taskade = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Taskade,
8
	projectId: string,
9
	body: {
10
		tasks:
11
			| ({ contentType: 'text/markdown' | 'text/plain'; content: string } & {
12
					taskId?: 'null'
13
					placement: 'afterbegin' | 'beforeend'
14
			  })
15
			| ({ contentType: 'text/markdown' | 'text/plain'; content: string } & {
16
					taskId: string
17
					placement: 'afterbegin' | 'beforeend' | 'beforebegin' | 'afterend'
18
			  }[])
19
	}
20
) {
21
	const url = new URL(`https://www.taskade.com/api/v1/projects/${projectId}/tasks/`)
22

23
	const response = await fetch(url, {
24
		method: 'POST',
25
		headers: {
26
			'Content-Type': 'application/json',
27
			Authorization: 'Bearer ' + auth.token
28
		},
29
		body: JSON.stringify(body)
30
	})
31

32
	if (!response.ok) {
33
		const text = await response.text()
34
		throw new Error(`${response.status} ${text}`)
35
	}
36

37
	return await response.json()
38
}
39