0

Download direct cost attachment

by
Published Oct 17, 2025

The *Download direct cost attachment* endpoint downloads a specific attachment for a given `directCostId` and `attachmentId`. [Direct costs](https://docs.codat.io/lending-api#/schemas/DirectCost) are business expenses that don't impact Accounts Payable.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Download direct cost attachment
7
 * The *Download direct cost attachment* endpoint downloads a specific attachment for a given `directCostId` and `attachmentId`.
8

9
[Direct costs](https://docs.codat.io/lending-api#/schemas/DirectCost) are business expenses that don't impact Accounts Payable.
10

11
 */
12
export async function main(
13
	auth: Codat,
14
	companyId: string,
15
	connectionId: string,
16
	directCostId: string,
17
	attachmentId: string
18
) {
19
	const url = new URL(
20
		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/data/directCosts/${directCostId}/attachments/${attachmentId}/download`
21
	)
22

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