0

Update an account group

by
Published Oct 17, 2025

Updates an existing account group by setting field values. Any fields not provided remain unchanged.

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 an account group
7
 * Updates an existing account group by setting field values. Any fields not provided remain unchanged.
8
 */
9
export async function main(
10
	auth: SageIntacct,
11
	key: string,
12
	body: {
13
		key?: string
14
		id?: string
15
		title?: string
16
		displayTotalLineAs?: string
17
		manager?: string
18
		calculationMethod?: 'period' | 'startOfPeriod' | 'endOfPeriod'
19
		normalBalance?: 'debit' | 'credit'
20
		groupType?:
21
			| 'accounts'
22
			| 'groups'
23
			| 'statisticalAccounts'
24
			| 'computation'
25
			| 'category'
26
			| 'statisticalCategory'
27
		isKPI?: false | true
28
		includeChildAmount?: false | true
29
		accountGroupPurpose?: { key?: string; id?: string; href?: string }
30
		reportFilters?: {
31
			location?: 'noFilter' | 'specificHierarchy' | 'specific' | 'nullValue'
32
			debitOrCredit?: 'both' | 'debitOnly' | 'creditOnly'
33
			department?: 'noFilter' | 'specificHierarchy' | 'specific' | 'nullValue'
34
			vendor?: 'noFilter' | 'specificHierarchy' | 'specific' | 'unspecified'
35
			customer?: 'noFilter' | 'specificHierarchy' | 'specific' | 'nullValue'
36
			project?: 'noFilter' | 'specificHierarchy' | 'specific' | 'nullValue'
37
			employee?: 'noFilter' | 'specificHierarchy' | 'specific' | 'nullValue'
38
			item?: 'noFilter' | 'specific' | 'nullValue'
39
			class?: 'noFilter' | 'specificHierarchy' | 'specific' | 'nullValue'
40
			contract?: 'noFilter' | 'specificHierarchy' | 'specific' | 'nullValue'
41
			task?: 'noFilter' | 'nullValue'
42
			warehouse?: 'noFilter' | 'specificHierarchy' | 'specific' | 'nullValue'
43
			costType?: 'noFilter' | 'nullValue'
44
			asset?: 'noFilter' | 'specificHierarchy' | 'specific' | 'nullValue'
45
			affiliateEntity?: 'noFilter' | 'specific' | 'nullValue'
46
		}
47
		dimensions?: {
48
			location?: { key?: string; id?: string; name?: string; href?: string }
49
			department?: { key?: string; id?: string; name?: string; href?: string }
50
			employee?: { key?: string; id?: string; name?: string; href?: string }
51
			project?: { key?: string; id?: string; name?: string; href?: string }
52
			customer?: { key?: string; id?: string; name?: string; href?: string }
53
			vendor?: { key?: string; id?: string; name?: string; href?: string }
54
			item?: { key?: string; id?: string; name?: string; href?: string }
55
			warehouse?: { key?: string; id?: string; name?: string; href?: string }
56
			class?: { key?: string; id?: string; name?: string; href?: string }
57
			task?: { id?: string; key?: string; name?: string; href?: string }
58
			costType?: { id?: string; key?: string; name?: string; href?: string }
59
			asset?: { id?: string; key?: string; name?: string; href?: string }
60
			contract?: { id?: string; key?: string; name?: string; href?: string }
61
			affiliateEntity?: {
62
				key?: string
63
				id?: string
64
				href?: string
65
				name?: string
66
			}
67
		} & {
68
			location?: { key?: string; id?: string; name?: string; href?: string }
69
			locationGroup?: {
70
				key?: string
71
				id?: string
72
				name?: string
73
				href?: string
74
			}
75
			department?: { key?: string; id?: string; name?: string; href?: string }
76
			departmentGroup?: {
77
				key?: string
78
				id?: string
79
				name?: string
80
				href?: string
81
			}
82
		}
83
		accountRanges?: {
84
			key?: string
85
			id?: string
86
			sortOrder?: number
87
			rangeFrom?: string
88
			rangeTo?: string
89
			glAccountGroup?: { key?: string; id?: string; href?: string }
90
			audit?: {
91
				createdDateTime?: string
92
				modifiedDateTime?: string
93
				createdBy?: string
94
				modifiedBy?: string
95
			}
96
			href?: string
97
		}[]
98
		statisticalAccountRanges?: {
99
			key?: string
100
			id?: string
101
			sortOrder?: number
102
			rangeFrom?: string
103
			rangeTo?: string
104
			glAccountGroup?: { key?: string; id?: string; href?: string }
105
			audit?: {
106
				createdDateTime?: string
107
				modifiedDateTime?: string
108
				createdBy?: string
109
				modifiedBy?: string
110
			}
111
			href?: string
112
		}[]
113
		accountGroupMembers?: {
114
			key?: string
115
			id?: string
116
			href?: string
117
			sortOrder?: number
118
			accountGroup?: { key?: string; id?: string; href?: string }
119
			glAccountGroup?: { key?: string; id?: string; href?: string }
120
			audit?: {
121
				createdDateTime?: string
122
				modifiedDateTime?: string
123
				createdBy?: string
124
				modifiedBy?: string
125
			}
126
		}[]
127
		accountGroupCategoryMembers?: {
128
			key?: string
129
			id?: string
130
			href?: string
131
			sortOrder?: number
132
			accountCategory?: { key?: string; id?: string; href?: string }
133
			glAccountGroup?: { key?: string; id?: string; href?: string }
134
			audit?: {
135
				createdDateTime?: string
136
				modifiedDateTime?: string
137
				createdBy?: string
138
				modifiedBy?: string
139
			}
140
		}[]
141
		statisticalAccountGroupCategoryMembers?: {
142
			key?: string
143
			id?: string
144
			href?: string
145
			sortOrder?: number
146
			accountCategory?: { key?: string; id?: string; href?: string }
147
			glAccountGroup?: { key?: string; id?: string; href?: string }
148
			audit?: {
149
				createdDateTime?: string
150
				modifiedDateTime?: string
151
				createdBy?: string
152
				modifiedBy?: string
153
			}
154
		}[]
155
		accountGroupComputation?: {
156
			key?: string
157
			id?: string
158
			href?: string
159
			formulaLeft?:
160
				| { glAccountGroup?: { id?: string; key?: string; href?: string } }
161
				| {
162
						glAccount?: {
163
							id?: string
164
							key?: string
165
							name?: string
166
							href?: string
167
						}
168
						asOf?: 'startOfPeriod' | 'endOfPeriod' | 'forPeriod'
169
				  }
170
				| { constant?: string }
171
			operator?: 'add' | 'subtract' | 'multiply' | 'divide'
172
			formulaRight?:
173
				| { glAccountGroup?: { id?: string; key?: string; href?: string } }
174
				| {
175
						glAccount?: {
176
							id?: string
177
							key?: string
178
							name?: string
179
							href?: string
180
						}
181
						asOf?: 'startOfPeriod' | 'endOfPeriod' | 'forPeriod'
182
				  }
183
				| { constant?: string }
184
			numberOfDecimalPlaces?: number
185
			displayAs?:
186
				| 'number'
187
				| 'percent'
188
				| 'ratioWithDecimals'
189
				| 'ratioWithoutDecimals'
190
				| 'dailyAverage'
191
				| 'weeklyAverage'
192
				| 'monthlyAverage'
193
				| 'quarterlyAverage'
194
			unit?: string
195
			unitPlacement?: 'left' | 'right'
196
			glAccountGroup?: { key?: string; id?: string; href?: string }
197
			audit?: {
198
				createdDateTime?: string
199
				modifiedDateTime?: string
200
				createdBy?: string
201
				modifiedBy?: string
202
			}
203
		}[]
204
		audit?: {
205
			createdDateTime?: string
206
			modifiedDateTime?: string
207
			createdBy?: string
208
			modifiedBy?: string
209
		}
210
		href?: string
211
	} & { id?: {} }
212
) {
213
	const url = new URL(
214
		`https://api.intacct.com/ia/api/v1/objects/general-ledger/account-group/${key}`
215
	)
216

217
	const response = await fetch(url, {
218
		method: 'PATCH',
219
		headers: {
220
			'Content-Type': 'application/json',
221
			Authorization: 'Bearer ' + auth.token
222
		},
223
		body: JSON.stringify(body)
224
	})
225
	if (!response.ok) {
226
		const text = await response.text()
227
		throw new Error(`${response.status} ${text}`)
228
	}
229
	return await response.json()
230
}
231