0

Update source account

by
Published Oct 17, 2025

The _Update source account_ endpoint updates a single source account for a single data connection connected to a single company. ### Tips and pitfalls * This endpoint only updates the `accountName` field. * Updates made here apply exclusively to source accounts and will not affect target accounts in the accounting software.

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 source account
7
 * The _Update source account_ endpoint updates a single source account for a single data connection connected to a single company.
8

9
### Tips and pitfalls
10

11
* This endpoint only updates the `accountName` field.
12
* Updates made here apply exclusively to source accounts and will not affect target accounts in the accounting software.
13
 */
14
export async function main(
15
	auth: Codat,
16
	companyId: string,
17
	connectionId: string,
18
	accountId: string,
19
	body: {
20
		id: string
21
		accountName: string
22
		accountType: 'checking' | 'savings' | 'loan' | 'creditCard' | 'prepaidCard'
23
		accountNumber: string
24
		sortCode?: string
25
		routingInfo?: {
26
			bankCode?: string
27
			type?:
28
				| 'rtn'
29
				| 'aba'
30
				| 'swift'
31
				| 'bsb'
32
				| 'iban'
33
				| 'nz2'
34
				| 'trno'
35
				| 'sortcode'
36
				| 'blz'
37
				| 'ifsc'
38
				| 'bankcode'
39
				| 'apca'
40
				| 'clabe'
41
		}
42
		currency: string
43
		balance: number
44
		accountInfo?: {
45
			description?: string
46
			nickname?: string
47
			accountOpenDate?: string
48
			availableBalance?: number
49
		}
50
		status?: 'pending' | 'connected' | 'connecting' | 'disconnected' | 'unknown'
51
		feedStartDate?: string
52
	}
53
) {
54
	const url = new URL(
55
		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/connectionInfo/bankFeedAccounts/${accountId}`
56
	)
57

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