Updates a specific manual journal
One script reply has been approved by the moderators Verified
Created by hugo697 448 days ago
Submitted by hugo697 Bun
Verified 448 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Updates a specific manual journal
7
 *
8
 */
9
export async function main(
10
	auth: Xero,
11
	ManualJournalID: string,
12
	xero_tenant_id: string,
13
	Idempotency_Key: string,
14
	body: {
15
		pagination?: {
16
			page?: number
17
			pageSize?: number
18
			pageCount?: number
19
			itemCount?: number
20
		}
21
		Warnings?: { Message?: string }[]
22
		ManualJournals?: {
23
			Narration: string
24
			JournalLines?: {
25
				LineAmount?: number
26
				AccountCode?: string
27
				AccountID?: string
28
				Description?: string
29
				TaxType?: string
30
				Tracking?: {
31
					TrackingCategoryID?: string
32
					TrackingOptionID?: string
33
					Name?: string
34
					Option?: string
35
					Status?: 'ACTIVE' | 'ARCHIVED' | 'DELETED'
36
					Options?: {
37
						TrackingOptionID?: string
38
						Name?: string
39
						Status?: 'ACTIVE' | 'ARCHIVED' | 'DELETED'
40
						TrackingCategoryID?: string
41
					}[]
42
				}[]
43
				TaxAmount?: number
44
				IsBlank?: false | true
45
			}[]
46
			Date?: string
47
			LineAmountTypes?: 'Exclusive' | 'Inclusive' | 'NoTax'
48
			Status?: 'ARCHIVED' | 'DELETED' | 'DRAFT' | 'POSTED' | 'VOIDED'
49
			Url?: string
50
			ShowOnCashBasisReports?: false | true
51
			HasAttachments?: never
52
			UpdatedDateUTC?: string
53
			ManualJournalID?: string
54
			StatusAttributeString?: string
55
			Warnings?: { Message?: string }[]
56
			ValidationErrors?: { Message?: string }[]
57
			Attachments?: {
58
				AttachmentID?: string
59
				FileName?: string
60
				Url?: string
61
				MimeType?: string
62
				ContentLength?: number
63
				IncludeOnline?: false | true
64
			}[]
65
		}[]
66
	}
67
) {
68
	const url = new URL(`https://api.xero.com/api.xro/2.0/ManualJournals/${ManualJournalID}`)
69

70
	const response = await fetch(url, {
71
		method: 'POST',
72
		headers: {
73
			Accept: 'application/json',
74
			'xero-tenant-id': xero_tenant_id,
75
			'Idempotency-Key': Idempotency_Key,
76
			'Content-Type': 'application/json',
77
			Authorization: 'Bearer ' + auth.token
78
		},
79
		body: JSON.stringify(body)
80
	})
81
	if (!response.ok) {
82
		const text = await response.text()
83
		throw new Error(`${response.status} ${text}`)
84
	}
85
	return await response.json()
86
}
87