0

List direct income attachments

by
Published Oct 17, 2025

The *List direct income attachments* endpoint returns a list of attachments available to download for given `directIncomeId`. [Direct incomes](https://docs.codat.io/lending-api#/schemas/DirectIncome) are incomes received directly from the business' operations at the point of the sale.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * List direct income attachments
7
 * The *List direct income attachments* endpoint returns a list of attachments available to download for given `directIncomeId`.
8

9
[Direct incomes](https://docs.codat.io/lending-api#/schemas/DirectIncome) are incomes received directly from the business' operations at the point of the sale.
10
 */
11
export async function main(
12
	auth: Codat,
13
	companyId: string,
14
	connectionId: string,
15
	directIncomeId: string
16
) {
17
	const url = new URL(
18
		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/data/directIncomes/${directIncomeId}/attachments`
19
	)
20

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