0

Get direct income attachment

by
Published Oct 17, 2025

The *Get direct income attachment* endpoint returns a specific attachment for a given `directIncomeId` and `attachmentId`. [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
 * Get direct income attachment
7
 * The *Get direct income attachment* endpoint returns a specific attachment for a given `directIncomeId` and `attachmentId`.
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
	attachmentId: string,
17
	timeoutInMinutes: string | undefined
18
) {
19
	const url = new URL(
20
		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/data/directIncomes/${directIncomeId}/attachments/${attachmentId}`
21
	)
22
	for (const [k, v] of [['timeoutInMinutes', timeoutInMinutes]]) {
23
		if (v !== undefined && v !== '' && k !== undefined) {
24
			url.searchParams.append(k, v)
25
		}
26
	}
27

28
	const response = await fetch(url, {
29
		method: 'GET',
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.json()
40
}
41