0

Get purchase order attachment

by
Published Oct 17, 2025

The *Get purchase order attachment* endpoint returns a specific attachment for a given `purchaseOrderId` and `attachmentId`. [Purchase Orders](https://docs.codat.io/accounting-api#/schemas/PurchaseOrder) represent a business's intent to purchase goods or services from a supplier.

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

9
[Purchase Orders](https://docs.codat.io/accounting-api#/schemas/PurchaseOrder) represent a business's intent to purchase goods or services from a supplier.
10

11
 */
12
export async function main(
13
	auth: Codat,
14
	companyId: string,
15
	connectionId: string,
16
	purchaseOrderId: string,
17
	attachmentId: string
18
) {
19
	const url = new URL(
20
		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/data/purchaseOrders/${purchaseOrderId}/attachments/${attachmentId}`
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.json()
35
}
36