Creates a new file association

By passing in the appropriate options, you can create a new 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
 * Creates a new file association
7
 * By passing in the appropriate options, you can create a new folder
8
 */
9
export async function main(
10
	auth: Xero,
11
	FileId: string,
12
	xero_tenant_id: string,
13
	Idempotency_Key: string,
14
	body: {
15
		SendWithObject?: false | true
16
		Name?: string
17
		Size?: number
18
		FileId?: string
19
		ObjectId?: string
20
		ObjectGroup?:
21
			| 'Account'
22
			| 'BankTransaction'
23
			| 'Contact'
24
			| 'CreditNote'
25
			| 'Invoice'
26
			| 'Item'
27
			| 'ManualJournal'
28
			| 'Overpayment'
29
			| 'Payment'
30
			| 'Prepayment'
31
			| 'Quote'
32
			| 'Receipt'
33
		ObjectType?:
34
			| 'Account'
35
			| 'Contact'
36
			| 'Prepayment'
37
			| 'Receipt'
38
			| 'Unknown'
39
			| 'Accpay'
40
			| 'AccPayCredit'
41
			| 'AccPayPayment'
42
			| 'AccRec'
43
			| 'AccRecCredit'
44
			| 'AccRecPayment'
45
			| 'Adjustment'
46
			| 'ApCreditPayment'
47
			| 'ApOverPayment'
48
			| 'ApOverPaymentPayment'
49
			| 'ApOverPaymentSourcePayment'
50
			| 'ApPrepayment'
51
			| 'ApPrepaymentPayment'
52
			| 'ApPrepaymentSourcePayment'
53
			| 'ArCreditPayment'
54
			| 'ArOverPayment'
55
			| 'ArOverpaymentPayment'
56
			| 'ArOverpaymentSourcePayment'
57
			| 'ArPrepayment'
58
			| 'ArPrepaymentPayment'
59
			| 'ArPrepaymentSourcePayment'
60
			| 'CashPaid'
61
			| 'CashRec'
62
			| 'ExpPayment'
63
			| 'ManJournal'
64
			| 'PurchaseOrder'
65
			| 'Transfer'
66
			| 'Business'
67
			| 'Employee'
68
			| 'Person'
69
			| 'User'
70
			| 'Org'
71
			| 'FixedAsset'
72
			| 'PayRun'
73
			| 'PriceListItem'
74
			| 'Bank'
75
			| 'Current'
76
			| 'Equity'
77
			| 'Expense'
78
			| 'Fixed'
79
			| 'Liability'
80
			| 'Revenue'
81
			| 'Sales'
82
			| 'Overheads'
83
			| 'Depreciatn'
84
			| 'OtherIncome'
85
			| 'DirectCosts'
86
			| 'Currliab'
87
			| 'Termliab'
88
			| 'NonCurrent'
89
			| 'SalesQuote'
90
	}
91
) {
92
	const url = new URL(`https://api.xero.com/files.xro/1.0//Files/${FileId}/Associations`)
93

94
	const response = await fetch(url, {
95
		method: 'POST',
96
		headers: {
97
			Accept: 'application/json',
98
			'xero-tenant-id': xero_tenant_id,
99
			'Idempotency-Key': Idempotency_Key,
100
			'Content-Type': 'application/json',
101
			Authorization: 'Bearer ' + auth.token
102
		},
103
		body: JSON.stringify(body)
104
	})
105
	if (!response.ok) {
106
		const text = await response.text()
107
		throw new Error(`${response.status} ${text}`)
108
	}
109
	return await response.json()
110
}
111