0

Delete task

by
Published Oct 17, 2025

Delete a specific task associated with the contract. Optionally, a reason can be provided for auditing or documentation purposes. **Token scopes**: `contracts:write`

Script deel Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Delete task
4
 * Delete a specific task associated with the contract. Optionally, a reason can be provided for auditing or documentation purposes.
5
 **Token scopes**: `contracts:write`
6
 */
7
export async function main(
8
	auth: RT.Deel,
9
	contract_id: string,
10
	task_id: string,
11
	reason?: string | undefined
12
) {
13
	const url = new URL(`https://api.letsdeel.com/rest/v2/contracts/${contract_id}/tasks/${task_id}`)
14
	for (const [k, v] of [['reason', reason]]) {
15
		if (v !== undefined && v !== '') {
16
			url.searchParams.append(k, v)
17
		}
18
	}
19
	const response = await fetch(url, {
20
		method: 'DELETE',
21
		headers: {
22
			Authorization: 'Bearer ' + auth.apiKey
23
		},
24
		body: undefined
25
	})
26
	if (!response.ok) {
27
		const text = await response.text()
28
		throw new Error(`${response.status} ${text}`)
29
	}
30
	return await response.json()
31
}
32