0

Task put date

by
Published Nov 5, 2024

Create or update date for a task

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
	taskId: string,
10
	body: {
11
		start: { date: string; time?: string; timezone?: string }
12
		end?: { date: string; time?: string; timezone?: string }
13
	}
14
) {
15
	const url = new URL(`https://www.taskade.com/api/v1/projects/${projectId}/tasks/${taskId}/date`)
16

17
	const response = await fetch(url, {
18
		method: 'PUT',
19
		headers: {
20
			'Content-Type': 'application/json',
21
			Authorization: 'Bearer ' + auth.token
22
		},
23
		body: JSON.stringify(body)
24
	})
25

26
	if (!response.ok) {
27
		const text = await response.text()
28
		throw new Error(`${response.status} ${text}`)
29
	}
30

31
	return await response.json()
32
}
33