Creates a time entry for a specific project

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

24
	const response = await fetch(url, {
25
		method: 'POST',
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.json()
40
}
41