0

Get bill attachment

by
Published Oct 17, 2025

The *Get bill attachment* endpoint returns a specific attachment for a given `billId` and `attachmentId`. [Bills](https://docs.codat.io/sync-for-payables-api#/schemas/Bill) are invoices that represent the SMB's financial obligations to their supplier for a purchase of goods or services. Check out our [coverage explorer](https://knowledge.codat.io/supported-features/accounting?view=tab-by-data-type&dataType=bills) for integrations that support getting a bill attachment.

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 bill attachment
7
 * The *Get bill attachment* endpoint returns a specific attachment for a given `billId` and `attachmentId`.
8

9
[Bills](https://docs.codat.io/sync-for-payables-api#/schemas/Bill) are invoices that represent the SMB's financial obligations to their supplier for a purchase of goods or services.
10

11
Check out our [coverage explorer](https://knowledge.codat.io/supported-features/accounting?view=tab-by-data-type&dataType=bills) for integrations that support getting a bill attachment.
12

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

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