0

Update a timesheet

by
Published Oct 17, 2025

Updates an existing timesheet by setting field values. Any fields not provided remain unchanged. Permissions and other requirements SubscriptionTime & Expenses User typeBusiness, Project Manager, or Employee PermissionsUpdate Timesheets

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

9

10
Permissions and other requirements
11

12
SubscriptionTime & Expenses
13
User typeBusiness, Project Manager, or Employee
14
PermissionsUpdate Timesheets
15

16

17

18

19
 */
20
export async function main(
21
	auth: SageIntacct,
22
	key: string,
23
	body: {
24
		key?: string
25
		id?: string
26
		href?: string
27
		beginDate?: string
28
		endDate?: string
29
		postingDate?: string
30
		state?:
31
			| 'submitted'
32
			| 'approved'
33
			| 'partiallyApproved'
34
			| 'declined'
35
			| 'draft'
36
			| 'partiallyDeclined'
37
			| 'saved'
38
		unitOfMeasure?: string
39
		hoursInDay?: number
40
		description?: string
41
		calculationMethod?: 'hourly' | 'salary'
42
		postActualLaborCost?: false | true
43
		employee?: { key?: string; id?: string; href?: string }
44
		employeeContact?: {
45
			key?: string
46
			id?: string
47
			firstName?: string
48
			lastName?: string
49
			href?: string
50
		}
51
		attachment?: { key?: string; id?: string; href?: string }
52
		lines?: {
53
			key?: string
54
			id?: string
55
			href?: string
56
			timesheet?: { key?: string; id?: string; href?: string }
57
			entryDate?: string
58
			quantity?: number
59
			lineNumber?: number
60
			description?: string
61
			notes?: string
62
			state?:
63
				| 'submitted'
64
				| 'approved'
65
				| 'partiallyApproved'
66
				| 'declined'
67
				| 'draft'
68
				| 'saved'
69
				| 'readyForApproval'
70
			timeType?: { key?: string; id?: string; href?: string }
71
			isBillable?: false | true
72
			isBilled?: 'true' | 'false' | 'partial'
73
			statisticalJournal?: { key?: string; id?: string; href?: string }
74
			billableUtilizedGLAccount?: { key?: string; id?: string; href?: string }
75
			nonBillableUtilizedGLAccount?: {
76
				key?: string
77
				id?: string
78
				href?: string
79
			}
80
			billableNonUtilizedGLAccount?: {
81
				key?: string
82
				id?: string
83
				href?: string
84
			}
85
			nonBillableNonUtilizedGLAccount?: {
86
				key?: string
87
				id?: string
88
				href?: string
89
			}
90
			hours?: {
91
				billable?: number
92
				nonBillable?: number
93
				approved?: number
94
				approvedBillable?: number
95
				approvedNonBillable?: number
96
				utilized?: number
97
				nonUtilized?: number
98
				approvedUtilized?: number
99
				approvedNonUtilized?: number
100
			}
101
			externalPayroll?: {
102
				costRate?: number
103
				billingRate?: number
104
				amount?: string
105
				employerTaxes?: number
106
				fringes?: number
107
				cashFringes?: number
108
			}
109
			laborClass?: { key?: string; id?: string; name?: string; href?: string }
110
			laborShift?: { key?: string; id?: string; name?: string; href?: string }
111
			laborUnion?: { key?: string; id?: string; name?: string; href?: string }
112
			dimensions?: {
113
				location?: { key?: string; id?: string; name?: string; href?: string }
114
				department?: {
115
					key?: string
116
					id?: string
117
					name?: string
118
					href?: string
119
				}
120
				employee?: { key?: string; id?: string; name?: string; href?: string }
121
				project?: { key?: string; id?: string; name?: string; href?: string }
122
				customer?: { key?: string; id?: string; name?: string; href?: string }
123
				vendor?: { key?: string; id?: string; name?: string; href?: string }
124
				item?: { key?: string; id?: string; name?: string; href?: string }
125
				warehouse?: { key?: string; id?: string; name?: string; href?: string }
126
				class?: { key?: string; id?: string; name?: string; href?: string }
127
				task?: { id?: string; key?: string; name?: string; href?: string }
128
				costType?: { id?: string; key?: string; name?: string; href?: string }
129
				asset?: { id?: string; key?: string; name?: string; href?: string }
130
				contract?: { id?: string; key?: string; name?: string; href?: string }
131
				affiliateEntity?: {
132
					key?: string
133
					id?: string
134
					href?: string
135
					name?: string
136
				}
137
			} & {
138
				location?: { key?: string; id?: string; name?: string; href?: string }
139
				department?: {
140
					key?: string
141
					id?: string
142
					name?: string
143
					href?: string
144
				}
145
			}
146
			audit?: {
147
				createdDateTime?: string
148
				modifiedDateTime?: string
149
				createdBy?: string
150
				modifiedBy?: string
151
			}
152
		}[]
153
		audit?: {
154
			createdDateTime?: string
155
			modifiedDateTime?: string
156
			createdBy?: string
157
			modifiedBy?: string
158
		}
159
		entity?: { key?: string; id?: string; name?: string; href?: string }
160
	} & { id?: {} }
161
) {
162
	const url = new URL(`https://api.intacct.com/ia/api/v1/objects/time/timesheet/${key}`)
163

164
	const response = await fetch(url, {
165
		method: 'PATCH',
166
		headers: {
167
			'Content-Type': 'application/json',
168
			Authorization: 'Bearer ' + auth.token
169
		},
170
		body: JSON.stringify(body)
171
	})
172
	if (!response.ok) {
173
		const text = await response.text()
174
		throw new Error(`${response.status} ${text}`)
175
	}
176
	return await response.json()
177
}
178