Creates a new folder
One script reply has been approved by the moderators Verified

By passing in the appropriate properties, you can create a new folder

Created by hugo697 448 days ago Picked 1 time
Submitted by hugo697 Bun
Verified 448 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Creates a new folder
7
 * By passing in the appropriate properties, you can create a new folder
8
 */
9
export async function main(
10
	auth: Xero,
11
	xero_tenant_id: string,
12
	Idempotency_Key: string,
13
	body: {
14
		Name?: string
15
		FileCount?: number
16
		Email?: string
17
		IsInbox?: false | true
18
		Id?: string
19
	}
20
) {
21
	const url = new URL(`https://api.xero.com/files.xro/1.0//Folders`)
22

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