Updates an existing folder

By passing in the appropriate ID and properties, you can update a folder

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 an existing folder
7
 * By passing in the appropriate ID and properties, you can update a folder
8
 */
9
export async function main(
10
	auth: Xero,
11
	FolderId: string,
12
	xero_tenant_id: string,
13
	Idempotency_Key: string,
14
	body: {
15
		Name?: string
16
		FileCount?: number
17
		Email?: string
18
		IsInbox?: false | true
19
		Id?: string
20
	}
21
) {
22
	const url = new URL(`https://api.xero.com/files.xro/1.0//Folders/${FolderId}`)
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.json()
40
}
41