0

Update a contract line

by
Published Oct 17, 2025

Updates an existing contract line 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 a contract line
7
 * Updates an existing contract line 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
		href?: string
16
		state?:
17
			| 'draft'
18
			| 'inProgress'
19
			| 'renewalOnly'
20
			| 'canceled'
21
			| 'notRenewed'
22
			| 'completed'
23
			| 'revalued'
24
			| 'closed'
25
			| 'renewalForecast'
26
		lineNumber?: number
27
		recurringBillingPeriod?: number
28
		startDate?: string
29
		endDate?: string
30
		cancelationDate?: string
31
		changeType?:
32
			| 'newMRR'
33
			| 'addOnMRR'
34
			| 'renewalUpgrade'
35
			| 'renewalDowngrade'
36
			| 'churnMRR'
37
			| 'downgrade'
38
		itemDescription?: string
39
		priceCalculationMemo?: string
40
		deliveryStatus?: 'delivered' | 'undelivered'
41
		deliveryDate?: string
42
		postingDate?: string
43
		lineType?: 'sale' | 'discount' | 'debook'
44
		memo?: string
45
		shipToSource?: 'contractValue' | 'userSpecifiedValue'
46
		billToSource?: 'contractValue' | 'userSpecifiedValue'
47
		revenueDeferralStatus?:
48
			| 'deferRevenueUntilItemIsDelivered'
49
			| 'deferRevenueUntilAllItemsAreDelivered'
50
		isRecurring?: false | true
51
		currency?: {
52
			exchangeRateDate?: string
53
			exchangeRate?: string
54
			baseCurrency?: string
55
			txnCurrency?: string
56
		}
57
		billing?: {
58
			amountFrequency?: 'oneTime' | 'useBillingTemplate' | 'includeWithEveryInvoice'
59
			template?: { key?: string; id?: string; method?: string; href?: string }
60
			schedule?: {
61
				key?: string
62
				id?: string
63
				status?:
64
					| 'draft'
65
					| 'inProgress'
66
					| 'completed'
67
					| 'renewalForecast'
68
					| 'onHold'
69
					| 'terminated'
70
					| 'estimateRevalued'
71
				href?: string
72
			}
73
			method?: 'fixedPrice' | 'quantityBased' | 'projectT&M' | 'projectTime' | 'projectMaterials'
74
			usageQuantityReset?: 'afterEachRenewal' | 'afterEachInvoice'
75
			isUsageQuantityRecurring?: false | true
76
			committedQuantityEndAction?: 'billUnusedQuantity' | 'cancelUnusedQuantity' | 'doNothing'
77
			committedQuantityExcess?: 'doNothing' | 'billOverage' | 'doNotAllowOverage'
78
			quantityType?: 'variable' | 'committed'
79
			durationInPeriods?: string
80
			proratePartialPeriods?: false | true
81
			frequency?: 'monthly' | 'quarterly' | 'annually'
82
			startDate?: string
83
			endDate?: string
84
			holdDate?: string
85
			resumeDate?: string
86
			memo?: string
87
			quantity?: string
88
			rate?: string
89
			multiplier?: string
90
			discount?: string
91
			flatFixedAmount?: string
92
			baseFlatFixedAmount?: string
93
			totalFlatFixedAmount?: string
94
			totalBaseFlatFixedAmount?: string
95
		}
96
		expense?: { holdDate?: string; resumeDate?: string; memo?: string }
97
		revenue?: {
98
			journal1?: {
99
				glJournal?: { key?: string; id?: string; name?: string; href?: string }
100
				revenueTemplate?: {
101
					key?: string
102
					id?: string
103
					recognitionMethod?: string
104
					href?: string
105
				}
106
				revenueSchedule?: {
107
					key?: string
108
					id?: string
109
					status?:
110
						| 'draft'
111
						| 'inProgress'
112
						| 'completed'
113
						| 'renewalForecast'
114
						| 'onHold'
115
						| 'terminated'
116
						| 'estimateRevalued'
117
						| 'pendingDelivery'
118
						| 'pendingDeliveryAll'
119
					href?: string
120
				}
121
				startDate?: string
122
				endDate?: string
123
			}
124
			journal2?: {
125
				glJournal?: { key?: string; id?: string; name?: string; href?: string }
126
				revenueTemplate?: {
127
					key?: string
128
					id?: string
129
					recognitionMethod?: string
130
					href?: string
131
				}
132
				revenueSchedule?: {
133
					key?: string
134
					id?: string
135
					status?:
136
						| 'draft'
137
						| 'inProgress'
138
						| 'completed'
139
						| 'renewalForecast'
140
						| 'onHold'
141
						| 'terminated'
142
						| 'estimateRevalued'
143
						| 'pendingDelivery'
144
						| 'pendingDeliveryAll'
145
					href?: string
146
				}
147
				startDate?: string
148
				endDate?: string
149
			}
150
			totalQuantity?: string
151
			resumeDate?: string
152
			holdDate?: string
153
			memo?: string
154
		}
155
		renewal?: {
156
			renew?: false | true
157
			billingTemplate?: { key?: string; id?: string; href?: string }
158
		}
159
		contacts?: {
160
			shipTo?: { key?: string; id?: string; href?: string }
161
			billTo?: { key?: string; id?: string; href?: string }
162
		}
163
		contract?: {
164
			key?: string
165
			id?: string
166
			endDate?: string
167
			termType?: string
168
			state?: 'draft' | 'inProgress' | 'canceled' | 'notRenewed' | 'renewed'
169
			name?: string
170
			href?: string
171
		}
172
		item?: { key?: string; id?: string; name?: string; href?: string }
173
		renewalTriggerDate?: string
174
		lineRenewalDate?: string
175
		parent?: { key?: string; id?: string; lineNumber?: string; href?: string }
176
		dimensions?: {
177
			location?: { key?: string; id?: string; name?: string; href?: string }
178
			department?: { key?: string; id?: string; name?: string; href?: string }
179
			class?: { key?: string; id?: string; name?: string; href?: string }
180
			task?: { id?: string; key?: string; name?: string; href?: string }
181
			vendor?: { key?: string; id?: string; name?: string; href?: string }
182
			customer?: { key?: string; id?: string; name?: string; href?: string }
183
			project?: { key?: string; id?: string; name?: string; href?: string }
184
			employee?: { key?: string; id?: string; name?: string; href?: string }
185
		}
186
		audit?: {
187
			createdDateTime?: string
188
			modifiedDateTime?: string
189
			createdBy?: string
190
			modifiedBy?: string
191
			createdByUser?: { key?: string; id?: string; href?: string }
192
			modifiedByUser?: { key?: string; id?: string; href?: string }
193
		}
194
	}
195
) {
196
	const url = new URL(`https://api.intacct.com/ia/api/v1/objects/contracts/contract-line/${key}`)
197

198
	const response = await fetch(url, {
199
		method: 'PATCH',
200
		headers: {
201
			'Content-Type': 'application/json',
202
			Authorization: 'Bearer ' + auth.token
203
		},
204
		body: JSON.stringify(body)
205
	})
206
	if (!response.ok) {
207
		const text = await response.text()
208
		throw new Error(`${response.status} ${text}`)
209
	}
210
	return await response.json()
211
}
212