0

Update a department group

by
Published Oct 17, 2025

Updates an existing department group by setting field values. Any fields not provided remain unchanged. New values for any arrays will replace the existing array.

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
 * Update a department group
7
 * Updates an existing department group by setting field values. Any fields not provided remain unchanged. New values for any arrays will replace the existing array.
8
 */
9
export async function main(
10
	auth: SageIntacct,
11
	key: string,
12
	body: {
13
		key?: string
14
		id?: string
15
		href?: string
16
		name?: string
17
		description?: string
18
		groupType?: 'all' | 'specific'
19
		memberFilter?: {
20
			object?: string
21
			filters?:
22
				| { $eq?: {} }
23
				| { $ne?: {} }
24
				| { $lt?: {} }
25
				| { $lte?: {} }
26
				| { $gt?: {} }
27
				| { $gte?: {} }
28
				| { $in?: {} }
29
				| { $notIn?: {} }
30
				| { $contains?: {} }
31
				| { $notContains?: {} }
32
				| { $startsWith?: {} }
33
				| { $notStartsWith?: {} }
34
				| { $endsWith?: {} }
35
				| { $notEndsWith?: {} }[]
36
			filterExpression?: string
37
			orderBy?: {}[]
38
			size?: number
39
		} & {}
40
		groupMembers?: {
41
			key?: string
42
			id?: string
43
			href?: string
44
			department?: { key?: string; id?: string; name?: string; href?: string }
45
			departmentGroup?: { key?: string; id?: string; href?: string }
46
			sortOrder?: number
47
			audit?: {
48
				createdDateTime?: string
49
				modifiedDateTime?: string
50
				createdBy?: string
51
				modifiedBy?: string
52
			}
53
		}[]
54
		isDimensionStructure?: false | true
55
		audit?: {
56
			createdDateTime?: string
57
			modifiedDateTime?: string
58
			createdBy?: string
59
			modifiedBy?: string
60
		}
61
	} & { id?: {} }
62
) {
63
	const url = new URL(
64
		`https://api.intacct.com/ia/api/v1/objects/company-config/department-group/${key}`
65
	)
66

67
	const response = await fetch(url, {
68
		method: 'PATCH',
69
		headers: {
70
			'Content-Type': 'application/json',
71
			Authorization: 'Bearer ' + auth.token
72
		},
73
		body: JSON.stringify(body)
74
	})
75
	if (!response.ok) {
76
		const text = await response.text()
77
		throw new Error(`${response.status} ${text}`)
78
	}
79
	return await response.json()
80
}
81