Updates a time entry for a specific project

Allows you to update time entry in a project

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
 * Updates a time entry for a specific project
7
 * Allows you to update time entry in a project
8
 */
9
export async function main(
10
	auth: Xero,
11
	projectId: string,
12
	timeEntryId: string,
13
	Xero_Tenant_Id: string,
14
	Idempotency_Key: string,
15
	body: {
16
		userId: string
17
		taskId: string
18
		dateUtc: string
19
		duration: number
20
		description?: string
21
	}
22
) {
23
	const url = new URL(
24
		`https://api.xero.com/projects.xro/2.0/Projects/${projectId}/Time/${timeEntryId}`
25
	)
26

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