0

Generate loan transactions report

by
Published Oct 17, 2025

The _Generate loan transactions_ endpoint requests the generation of the Loan Transactions report. Learn more about Codat's liabilities feature [here](https://docs.codat.io/lending/features/liabilities-overview). Make sure you have [synced a company](https://docs.codat.io/lending-api#/operations/refresh-company-data) recently before calling the endpoint.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Generate loan transactions report
7
 * The _Generate loan transactions_ endpoint requests the generation of the Loan Transactions report.
8

9
Learn more about Codat's liabilities feature [here](https://docs.codat.io/lending/features/liabilities-overview).
10

11
Make sure you have [synced a company](https://docs.codat.io/lending-api#/operations/refresh-company-data) recently before calling the endpoint.
12

13
 */
14
export async function main(
15
	auth: Codat,
16
	companyId: string,
17
	sourceType: 'banking' | 'commerce' | 'accounting' | undefined
18
) {
19
	const url = new URL(
20
		`https://api.codat.io/companies/${companyId}/reports/liabilities/loans/transactions`
21
	)
22
	for (const [k, v] of [['sourceType', sourceType]]) {
23
		if (v !== undefined && v !== '' && k !== undefined) {
24
			url.searchParams.append(k, v)
25
		}
26
	}
27

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