0

Create a cost type

by
Published Oct 17, 2025

Creates a new cost type.

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 a cost type
7
 * Creates a new cost type.
8
 */
9
export async function main(
10
	auth: SageIntacct,
11
	body: {
12
		key?: string
13
		id?: string
14
		href?: string
15
		name?: string
16
		description?: string
17
		project?: { key?: string; id?: string; name?: string; href?: string }
18
		task?: { key?: string; id?: string; name?: string; href?: string }
19
		accumulationType?: { key?: string; id?: string; href?: string }
20
		costUnitDescription?: string
21
		glAccount?: { key?: string; id?: string; name?: string; href?: string }
22
		parent?: { key?: string; id?: string; name?: string; href?: string }
23
		item?: { key?: string; id?: string; name?: string; href?: string }
24
		planned?: { startDate?: string; endDate?: string }
25
		actual?: { startDate?: string; endDate?: string }
26
		status?: 'active' | 'inactive'
27
		root?: { key?: string; id?: string; name?: string; href?: string }
28
		standardCostType?: {
29
			key?: string
30
			id?: string
31
			name?: string
32
			href?: string
33
		}
34
		audit?: {
35
			createdDateTime?: string
36
			modifiedDateTime?: string
37
			createdBy?: string
38
			modifiedBy?: string
39
		}
40
	} & {}
41
) {
42
	const url = new URL(`https://api.intacct.com/ia/api/v1/objects/construction/cost-type`)
43

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