Update a file

Updates file properties of a single file

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
 * Update a file
7
 * Updates file properties of a single file
8
 */
9
export async function main(
10
	auth: Xero,
11
	FileId: string,
12
	xero_tenant_id: string,
13
	Idempotency_Key: string,
14
	body: {
15
		Name?: string
16
		MimeType?: string
17
		Size?: number
18
		CreatedDateUtc?: string
19
		UpdatedDateUtc?: string
20
		User?: {
21
			Id: string
22
			Name?: string
23
			FirstName?: string
24
			LastName?: string
25
			FullName?: string
26
		}
27
		Id?: string
28
		FolderId?: string
29
	}
30
) {
31
	const url = new URL(`https://api.xero.com/files.xro/1.0//Files/${FileId}`)
32

33
	const response = await fetch(url, {
34
		method: 'PUT',
35
		headers: {
36
			Accept: 'application/json',
37
			'xero-tenant-id': xero_tenant_id,
38
			'Idempotency-Key': Idempotency_Key,
39
			'Content-Type': 'application/json',
40
			Authorization: 'Bearer ' + auth.token
41
		},
42
		body: JSON.stringify(body)
43
	})
44
	if (!response.ok) {
45
		const text = await response.text()
46
		throw new Error(`${response.status} ${text}`)
47
	}
48
	return await response.json()
49
}
50