0

Create account

by
Published Oct 17, 2025

The *Create account* endpoint creates a new [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 account
7
 * The *Create account* endpoint creates a new [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
		nominalCode?: string
16
		name?: string
17
		description?: string
18
		fullyQualifiedCategory?: string
19
		fullyQualifiedName?: string
20
		currency?: string
21
		currentBalance?: number
22
		type?: 'Unknown' | 'Asset' | 'Expense' | 'Income' | 'Liability' | 'Equity'
23
		status?: 'Unknown' | 'Active' | 'Archived' | 'Pending'
24
		isBankAccount?: false | true
25
		validDatatypeLinks?: { property?: string; links?: string[] }[]
26
		supplementalData?: { content?: {} }
27
	}
28
) {
29
	const url = new URL(
30
		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/push/accounts`
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