0

Get loan summaries

by
Published Oct 17, 2025

The *Get loan summaries* endpoint returns a summary by integration type of all loans identified from a company's accounting, banking, and commerce integrations. The endpoint returns a list of a company's [loan summaries](https://docs.codat.io/lending-api#/schemas/LoanSummary) for each valid data connection. 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
 * Get loan summaries
7
 * The *Get loan summaries* endpoint returns a summary by integration type of all loans identified from a company's accounting, banking, and commerce integrations.
8

9
The endpoint returns a list of a company's [loan summaries](https://docs.codat.io/lending-api#/schemas/LoanSummary) for each valid data connection.
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(`https://api.codat.io/companies/${companyId}/reports/liabilities/loans`)
20
	for (const [k, v] of [['sourceType', sourceType]]) {
21
		if (v !== undefined && v !== '' && k !== undefined) {
22
			url.searchParams.append(k, v)
23
		}
24
	}
25

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