0

Create bank transactions

by
Published Oct 17, 2025

The *Create bank transactions* endpoint creates new [bank transactions](https://docs.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Create bank transactions
7
 * The *Create bank transactions* endpoint creates new [bank transactions](https://docs.
8
 */
9
export async function main(
10
	auth: Codat,
11
	companyId: string,
12
	connectionId: string,
13
	accountId: string,
14
	timeoutInMinutes: string | undefined,
15
	allowSyncOnPushComplete: string | undefined,
16
	body: {
17
		accountId: string
18
		transactions: {
19
			id: string
20
			date: string
21
			description?: string
22
			counterparty?: string
23
			reference?: string
24
			reconciled?: false | true
25
			amount: number
26
			balance?: number
27
			transactionType?:
28
				| 'Unknown'
29
				| 'Credit'
30
				| 'Debit'
31
				| 'Int'
32
				| 'Div'
33
				| 'Fee'
34
				| 'SerChg'
35
				| 'Dep'
36
				| 'Atm'
37
				| 'Pos'
38
				| 'Xfer'
39
				| 'Check'
40
				| 'Payment'
41
				| 'Cash'
42
				| 'DirectDep'
43
				| 'DirectDebit'
44
				| 'RepeatPmt'
45
				| 'Other'
46
		}[]
47
	}
48
) {
49
	const url = new URL(
50
		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/push/bankAccounts/${accountId}/bankTransactions`
51
	)
52
	for (const [k, v] of [
53
		['timeoutInMinutes', timeoutInMinutes],
54
		['allowSyncOnPushComplete', allowSyncOnPushComplete]
55
	]) {
56
		if (v !== undefined && v !== '' && k !== undefined) {
57
			url.searchParams.append(k, v)
58
		}
59
	}
60

61
	const response = await fetch(url, {
62
		method: 'POST',
63
		headers: {
64
			'Content-Type': 'application/json',
65
			Authorization: `Basic ${auth.encodedKey}`
66
		},
67
		body: JSON.stringify(body)
68
	})
69
	if (!response.ok) {
70
		const text = await response.text()
71
		throw new Error(`${response.status} ${text}`)
72
	}
73
	return await response.json()
74
}
75