0

Get categorized profit and loss statement

by
Published Oct 17, 2025

The *Get categorized profit and loss statement* endpoint returns a list of categorized accounts that appear on a company’s Profit and Loss statement. It also includes a balance as of the financial statement date. Codat suggests a category for each account automatically, but you can [change it](https://docs.codat.io/lending/features/financial-statements-overview#recategorizing-accounts) to a more suitable one.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Get categorized profit and loss statement
7
 * The *Get categorized profit and loss statement* endpoint returns a list of categorized accounts that appear on a company’s Profit and Loss statement. It also includes a balance as of the financial statement date.
8

9
Codat suggests a category for each account automatically, but you can [change it](https://docs.codat.io/lending/features/financial-statements-overview#recategorizing-accounts) to a more suitable one.
10
 */
11
export async function main(
12
	auth: Codat,
13
	companyId: string,
14
	reportDate: string | undefined,
15
	numberOfPeriods: string | undefined
16
) {
17
	const url = new URL(
18
		`https://api.codat.io/companies/${companyId}/reports/enhancedProfitAndLoss/accounts`
19
	)
20
	for (const [k, v] of [
21
		['reportDate', reportDate],
22
		['numberOfPeriods', numberOfPeriods]
23
	]) {
24
		if (v !== undefined && v !== '' && k !== undefined) {
25
			url.searchParams.append(k, v)
26
		}
27
	}
28

29
	const response = await fetch(url, {
30
		method: 'GET',
31
		headers: {
32
			Authorization: `Basic ${auth.encodedKey}`
33
		},
34
		body: undefined
35
	})
36
	if (!response.ok) {
37
		const text = await response.text()
38
		throw new Error(`${response.status} ${text}`)
39
	}
40
	return await response.json()
41
}
42