0

Create bank account

by
Published Oct 17, 2025

The *Create bank account* endpoint creates a new [bank account](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 account
7
 * The *Create bank account* endpoint creates a new [bank account](https://docs.
8
 */
9
export async function main(
10
	auth: Codat,
11
	companyId: string,
12
	connectionId: string,
13
	timeoutInMinutes: string | undefined,
14
	body: {
15
		accountName?: string
16
		accountType?: 'Unknown' | 'Credit' | 'Debit'
17
		nominalCode?: string
18
		sortCode?: string
19
		accountNumber?: string
20
		iBan?: string
21
		currency?: string
22
		balance?: number
23
		institution?: string
24
		availableBalance?: number
25
		overdraftLimit?: number
26
		status?: 'Unknown' | 'Active' | 'Archived' | 'Pending'
27
	}
28
) {
29
	const url = new URL(
30
		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/push/bankAccounts`
31
	)
32
	for (const [k, v] of [['timeoutInMinutes', timeoutInMinutes]]) {
33
		if (v !== undefined && v !== '' && k !== undefined) {
34
			url.searchParams.append(k, v)
35
		}
36
	}
37

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