Allows you to update a task

Allows you to update a specific task

Script xero Verified

by hugo697 ยท 12/20/2024

The script

Submitted by hugo697 Bun
Verified 515 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Allows you to update a task
7
 * Allows you to update a specific task
8
 */
9
export async function main(
10
	auth: Xero,
11
	projectId: string,
12
	taskId: string,
13
	Xero_Tenant_Id: string,
14
	Idempotency_Key: string,
15
	body: {
16
		name: string
17
		rate: number
18
		chargeType: 'TIME' | 'FIXED' | 'NON_CHARGEABLE'
19
		estimateMinutes?: number
20
	}
21
) {
22
	const url = new URL(`https://api.xero.com/projects.xro/2.0/Projects/${projectId}/Tasks/${taskId}`)
23

24
	const response = await fetch(url, {
25
		method: 'PUT',
26
		headers: {
27
      Accept: 'application/json',
28
			'Xero-Tenant-Id': Xero_Tenant_Id,
29
			'Idempotency-Key': Idempotency_Key,
30
			'Content-Type': 'application/json',
31
			Authorization: 'Bearer ' + auth.token
32
		},
33
		body: JSON.stringify(body)
34
	})
35
	if (!response.ok) {
36
		const text = await response.text()
37
		throw new Error(`${response.status} ${text}`)
38
	}
39
	return await response.text()
40
}
41