0

Update a project estimate

by
Published Oct 17, 2025

Updates an existing project estimate by setting field values. Any fields not provided remain unchanged. If the `budget` reference is change when `isPosted` is `true`, the estimate is unposted from the first budget and posted to the new budget.

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 project estimate
7
 * Updates an existing project estimate by setting field values. Any fields not provided remain unchanged. 
8

9
If the `budget` reference is change when `isPosted` is `true`, the estimate is unposted from the first budget and posted to the new budget.
10

11
 */
12
export async function main(
13
	auth: SageIntacct,
14
	key: string,
15
	body: {
16
		key?: string
17
		id?: string
18
		href?: string
19
		description?: string
20
		postTo?: 'firstPeriod' | 'estimateDate' | 'effectiveDate' | 'allPeriods'
21
		totalEstimateAmount?: string
22
		status?: 'active' | 'inactive' | 'finalized'
23
		isPrimary?: false | true
24
		isPosted?: false | true
25
		estimateDate?: string
26
		currency?: string
27
		budget?: { key?: string; id?: string; href?: string }
28
		project?: {
29
			key?: string
30
			id?: string
31
			name?: string
32
			startDate?: string
33
			endDate?: string
34
			href?: string
35
		}
36
		projectEstimateType?: {
37
			key?: string
38
			id?: string
39
			workflowTypes?:
40
				| 'original'
41
				| 'revision'
42
				| 'forecast'
43
				| 'approvedChange'
44
				| 'pendingChange'
45
				| 'other'[]
46
			href?: string
47
		}
48
		location?: { key?: string; id?: string; name?: string; href?: string }
49
		parentProject?: { key?: string; id?: string; name?: string; href?: string }
50
		customer?: { key?: string; id?: string; name?: string; href?: string }
51
		projectEstimateLines?: {
52
			key?: string
53
			id?: string
54
			href?: string
55
			amount?: string
56
			quantity?: string
57
			unitCost?: string
58
			currency?: string
59
			memo?: string
60
			lineNumber?: number
61
			externalUOM?: string
62
			workflowType?:
63
				| 'original'
64
				| 'revision'
65
				| 'forecast'
66
				| 'approvedChange'
67
				| 'pendingChange'
68
				| 'other'
69
			isPosted?: false | true
70
			effectiveDate?: string
71
			numberOfProductionUnits?: number
72
			productionUnitDescription?: string
73
			projectEstimate?: { key?: string; id?: string; href?: string }
74
			glAccount?: { key?: string; id?: string; name?: string; href?: string }
75
			changeRequest?: { key?: string; id?: string; href?: string }
76
			changeRequestLine?: { key?: string; id?: string; href?: string }
77
			dimensions?: {
78
				location?: { key?: string; id?: string; name?: string; href?: string }
79
				department?: {
80
					key?: string
81
					id?: string
82
					name?: string
83
					href?: string
84
				}
85
				employee?: { key?: string; id?: string; name?: string; href?: string }
86
				project?: { key?: string; id?: string; name?: string; href?: string }
87
				customer?: { key?: string; id?: string; name?: string; href?: string }
88
				vendor?: { key?: string; id?: string; name?: string; href?: string }
89
				item?: { key?: string; id?: string; name?: string; href?: string }
90
				warehouse?: { key?: string; id?: string; name?: string; href?: string }
91
				class?: { key?: string; id?: string; name?: string; href?: string }
92
				task?: { id?: string; key?: string; name?: string; href?: string }
93
				costType?: { id?: string; key?: string; name?: string; href?: string }
94
				asset?: { id?: string; key?: string; name?: string; href?: string }
95
				contract?: { id?: string; key?: string; name?: string; href?: string }
96
				affiliateEntity?: {
97
					key?: string
98
					id?: string
99
					href?: string
100
					name?: string
101
				}
102
			} & {
103
				department?: { key?: string; id?: string; name?: string }
104
				location?: {
105
					key?: string
106
					id?: string
107
					name?: string
108
					href?: string
109
				} & { id?: string }
110
			}
111
			audit?: {
112
				createdDateTime?: string
113
				modifiedDateTime?: string
114
				createdBy?: string
115
				modifiedBy?: string
116
			}
117
		}[]
118
		attachment?: { key?: string; id?: string; href?: string }
119
		audit?: {
120
			createdDateTime?: string
121
			modifiedDateTime?: string
122
			createdBy?: string
123
			modifiedBy?: string
124
		}
125
		entity?: { key?: string; id?: string; name?: string; href?: string }
126
	} & { id?: {} }
127
) {
128
	const url = new URL(
129
		`https://api.intacct.com/ia/api/v1/objects/construction/project-estimate/${key}`
130
	)
131

132
	const response = await fetch(url, {
133
		method: 'PATCH',
134
		headers: {
135
			'Content-Type': 'application/json',
136
			Authorization: 'Bearer ' + auth.token
137
		},
138
		body: JSON.stringify(body)
139
	})
140
	if (!response.ok) {
141
		const text = await response.text()
142
		throw new Error(`${response.status} ${text}`)
143
	}
144
	return await response.json()
145
}
146