0

Create an attachment

by
Published Oct 17, 2025

Creates a new attachment in a specified folder. The folder must exist before you create the attachment. You can add files when you create an attachment, or use a PATCH request to add files later. Permissions and other requirements SubscriptionCompany User typeBusiness PermissionsAdd Attachments

Script sage_intacct Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type SageIntacct = {
3
	token: string
4
}
5
/**
6
 * Create an attachment
7
 * Creates a new attachment in a specified folder. The folder must exist before you create the attachment. You can add files when you create an attachment, or use a PATCH request to add files later.
8

9

10
Permissions and other requirements
11

12
SubscriptionCompany
13
User typeBusiness
14
PermissionsAdd Attachments
15

16

17

18

19
 */
20
export async function main(
21
	auth: SageIntacct,
22
	body: {
23
		key?: string
24
		id?: string
25
		name?: string
26
		description?: string
27
		href?: string
28
		folder?: { key?: string; id?: string; href?: string }
29
		entity?: { key?: string; id?: string; name?: string; href?: string }
30
		files?: {
31
			key?: string
32
			id?: string
33
			href?: string
34
			name?: string
35
			size?: number
36
			data?: string
37
			attachment?: { id?: string; key?: string; href?: string }
38
		}[]
39
		audit?: {
40
			createdDate?: string
41
			modifiedDate?: string
42
			createdBy?: string
43
			modifiedBy?: string
44
		}
45
	} & {}
46
) {
47
	const url = new URL(`https://api.intacct.com/ia/api/v1/objects/company-config/attachment`)
48

49
	const response = await fetch(url, {
50
		method: 'POST',
51
		headers: {
52
			'Content-Type': 'application/json',
53
			Authorization: 'Bearer ' + auth.token
54
		},
55
		body: JSON.stringify(body)
56
	})
57
	if (!response.ok) {
58
		const text = await response.text()
59
		throw new Error(`${response.status} ${text}`)
60
	}
61
	return await response.json()
62
}
63