0

Create source account

by
Published Oct 17, 2025

The _Create Source Account_ endpoint allows you to create a representation of a bank account within Codat's domain.

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 source account
7
 * The _Create Source Account_ endpoint allows you to create a representation of a bank account within Codat's domain.
8
 */
9
export async function main(
10
	auth: Codat,
11
	companyId: string,
12
	connectionId: string,
13
	body:
14
		| {
15
				id: string
16
				accountName: string
17
				accountType: 'checking' | 'savings' | 'loan' | 'creditCard' | 'prepaidCard'
18
				accountNumber: string
19
				routingInfo?: {
20
					bankCode?: string
21
					type?:
22
						| 'rtn'
23
						| 'aba'
24
						| 'swift'
25
						| 'bsb'
26
						| 'iban'
27
						| 'nz2'
28
						| 'trno'
29
						| 'sortcode'
30
						| 'blz'
31
						| 'ifsc'
32
						| 'bankcode'
33
						| 'apca'
34
						| 'clabe'
35
				}
36
				sortCode?: string
37
				currency: string
38
				balance: number
39
				modifiedDate?: string
40
				accountInfo?: {
41
					description?: string
42
					nickname?: string
43
					accountOpenDate?: string
44
					availableBalance?: number
45
				}
46
		  }
47
		| {
48
				id: string
49
				accountName?: string
50
				accountType?: string
51
				accountNumber?: string
52
				sortCode?: string
53
				currency?: string
54
				balance?: number
55
				modifiedDate?: string
56
		  }
57
) {
58
	const url = new URL(
59
		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/connectionInfo/bankFeedAccounts`
60
	)
61

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