0

Update expense transactions

by
Published Oct 17, 2025

Update an expense transaction

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Update expense transactions
7
 * Update an expense transaction
8
 */
9
export async function main(
10
	auth: Codat,
11
	companyId: string,
12
	transactionId: string,
13
	body: {
14
		type: '#/definitions/expenseType'
15
		issueDate: string
16
		currency?: string
17
		currencyRate?: number
18
		contactRef?: { id?: string; contactType?: 'Supplier' }
19
		merchantName?: string
20
		lines?: {
21
			netAmount: number
22
			taxAmount: number
23
			taxRateRef?: { id?: string }
24
			accountRef: { id?: string }
25
			trackingRefs?: { id?: string }[]
26
		}[]
27
		notes?: string
28
	}
29
) {
30
	const url = new URL(
31
		`https://api.codat.io/companies/${companyId}/sync/expenses/expense-transactions/${transactionId}`
32
	)
33

34
	const response = await fetch(url, {
35
		method: 'PUT',
36
		headers: {
37
			'Content-Type': 'application/json',
38
			Authorization: `Basic ${auth.encodedKey}`
39
		},
40
		body: JSON.stringify(body)
41
	})
42
	if (!response.ok) {
43
		const text = await response.text()
44
		throw new Error(`${response.status} ${text}`)
45
	}
46
	return await response.json()
47
}
48