0

List invoice attachments

by
Published Oct 17, 2025

The *List invoice attachments* endpoint returns a list of attachments available to download for given `invoiceId`. [Invoices](https://docs.codat.io/lending-api#/schemas/Invoice) are itemized records of goods sold or services provided to a customer.

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 invoice attachments
7
 * The *List invoice attachments* endpoint returns a list of attachments available to download for given `invoiceId`.
8

9
[Invoices](https://docs.codat.io/lending-api#/schemas/Invoice) are itemized records of goods sold or services provided to a customer.
10
 */
11
export async function main(
12
	auth: Codat,
13
	companyId: string,
14
	connectionId: string,
15
	invoiceId: string
16
) {
17
	const url = new URL(
18
		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/data/invoices/${invoiceId}/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