0
Reverts a specific timesheet to draft
One script reply has been approved by the moderators Verified
Created by hugo697 208 days ago Viewed 13468 times
0
Submitted by hugo697 Bun
Verified 208 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Reverts a specific timesheet to draft
7
 *
8
 */
9
export async function main(
10
	auth: Xero,
11
	TimesheetID: string,
12
	Xero_Tenant_Id: string,
13
	Idempotency_Key: string
14
) {
15
	const url = new URL(
16
		`https://api.xero.com/payroll.xro/2.0/Timesheets/${TimesheetID}/RevertToDraft`
17
	)
18

19
	const response = await fetch(url, {
20
		method: 'POST',
21
		headers: {
22
			Accept: 'application/json',
23
			'Xero-Tenant-Id': Xero_Tenant_Id,
24
			'Idempotency-Key': Idempotency_Key,
25
			Authorization: 'Bearer ' + auth.token
26
		},
27
		body: undefined
28
	})
29
	if (!response.ok) {
30
		const text = await response.text()
31
		throw new Error(`${response.status} ${text}`)
32
	}
33
	return await response.json()
34
}
35