0

Create shifts

by
Published Oct 17, 2025

Creates multiple time tracking shifts for a contract, supporting both regular shift submissions and corrections that adjust hours for previously processed shifts. **Token scopes**: `time-tracking:write`

Script deel Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Create shifts
4
 * Creates multiple time tracking shifts for a contract, supporting both regular shift submissions and corrections that adjust hours for previously processed shifts.
5
 **Token scopes**: `time-tracking:write`
6
 */
7
export async function main(auth: RT.Deel, body: Body) {
8
	const url = new URL(`https://api.letsdeel.com/rest/v2/time_tracking/shifts`)
9

10
	const response = await fetch(url, {
11
		method: 'POST',
12
		headers: {
13
			'Content-Type': 'application/json',
14
			Authorization: 'Bearer ' + auth.apiKey
15
		},
16
		body: JSON.stringify(body)
17
	})
18
	if (!response.ok) {
19
		const text = await response.text()
20
		throw new Error(`${response.status} ${text}`)
21
	}
22
	return await response.json()
23
}
24

25
/* eslint-disable */
26
/**
27
 * This file was automatically generated by json-schema-to-typescript.
28
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
29
 * and run json-schema-to-typescript to regenerate this file.
30
 */
31

32
export interface Body {
33
	data: {
34
		shifts: (
35
			| RegularShiftRECOMMENDED
36
			| CorrectionAbsoluteShiftRECOMMENDED
37
			| CorrectionDeltaShiftRECOMMENDED
38
			| RegularShiftNOTRECOMMENDEDLEGACY
39
			| CorrectionAbsoluteShiftNOTRECOMMENDEDLEGACY
40
			| CorrectionDeltaShiftNOTRECOMMENDEDLEGACY
41
		)[]
42
		/**
43
		 * The unique identifier of the employee contract.
44
		 */
45
		contract_id: string
46
		[k: string]: unknown
47
	}
48
	[k: string]: unknown
49
}
50
export interface RegularShiftRECOMMENDED {
51
	summary: {
52
		/**
53
		 * Time unit
54
		 */
55
		time_unit: 'HOUR' | 'MONTH' | 'DAY' | 'WEEK'
56
		/**
57
		 * Time amount
58
		 */
59
		time_amount: number
60
		/**
61
		 * Shift Rate external ID
62
		 */
63
		shift_rate_external_id: string
64
		[k: string]: unknown
65
	}
66
	/**
67
	 * Type of the shift
68
	 */
69
	shift_type?: 'REGULAR'
70
	/**
71
	 * Description of the shift.
72
	 */
73
	description: string
74
	/**
75
	 * External ID of the shift.
76
	 */
77
	external_id: string
78
	/**
79
	 * Date of shift work
80
	 */
81
	date_of_work: string
82
	payroll_cycle_ref?: {
83
		/**
84
		 * Date in ISO 8601 format that helps referencing a payroll cycle
85
		 */
86
		date: string
87
		[k: string]: unknown
88
	}
89
	[k: string]: unknown
90
}
91
export interface CorrectionAbsoluteShiftRECOMMENDED {
92
	summary: {
93
		/**
94
		 * Time amount
95
		 */
96
		time_amount: number
97
		[k: string]: unknown
98
	}
99
	/**
100
	 * Type of the shift
101
	 */
102
	shift_type: 'CORRECTION_ABSOLUTE'
103
	/**
104
	 * Description of the correction shift.
105
	 */
106
	description: string
107
	/**
108
	 * External ID of the correction shift.
109
	 */
110
	external_id: string
111
	payroll_cycle_ref?: {
112
		/**
113
		 * Date in ISO 8601 format that helps referencing a payroll cycle
114
		 */
115
		date: string
116
		[k: string]: unknown
117
	}
118
	/**
119
	 * External ID of the original shift being corrected
120
	 */
121
	shift_reference_id: string
122
	[k: string]: unknown
123
}
124
export interface CorrectionDeltaShiftRECOMMENDED {
125
	/**
126
	 * Type of the shift
127
	 */
128
	shift_type: 'CORRECTION_DELTA'
129
	corrections: {
130
		/**
131
		 * Type of correction
132
		 */
133
		type: 'SUBTRACTION' | 'ADDITION'
134
		/**
135
		 * Time amount
136
		 */
137
		time_amount: number
138
		[k: string]: unknown
139
	}[]
140
	/**
141
	 * Description of the correction shift.
142
	 */
143
	description: string
144
	/**
145
	 * External ID of the correction shift.
146
	 */
147
	external_id: string
148
	payroll_cycle_ref?: {
149
		/**
150
		 * Date in ISO 8601 format that helps referencing a payroll cycle
151
		 */
152
		date: string
153
		[k: string]: unknown
154
	}
155
	/**
156
	 * External ID of the original shift being corrected
157
	 */
158
	shift_reference_id: string
159
	[k: string]: unknown
160
}
161
export interface RegularShiftNOTRECOMMENDEDLEGACY {
162
	summary: {
163
		/**
164
		 * Total break hours
165
		 */
166
		total_break_hours?: number
167
		/**
168
		 * Payable break hours
169
		 */
170
		payable_break_hours?: number
171
		/**
172
		 * Total payable hours
173
		 */
174
		total_payable_hours: number
175
		/**
176
		 * Shift duration hours
177
		 */
178
		shift_duration_hours?: number
179
		/**
180
		 * Shift Rate external ID
181
		 */
182
		shift_rate_external_id: string
183
		[k: string]: unknown
184
	}
185
	/**
186
	 * Type of the shift
187
	 */
188
	shift_type?: 'REGULAR'
189
	/**
190
	 * Description of the shift.
191
	 */
192
	description: string
193
	/**
194
	 * External ID of the shift.
195
	 */
196
	external_id: string
197
	/**
198
	 * Date of shift work
199
	 */
200
	date_of_work: string
201
	payroll_cycle_ref?: {
202
		/**
203
		 * Date in ISO 8601 format that helps referencing a payroll cycle
204
		 */
205
		date: string
206
		[k: string]: unknown
207
	}
208
	[k: string]: unknown
209
}
210
export interface CorrectionAbsoluteShiftNOTRECOMMENDEDLEGACY {
211
	summary: {
212
		/**
213
		 * Absolute total break hours
214
		 */
215
		total_break_hours?: number
216
		/**
217
		 * Absolute payable break hours
218
		 */
219
		payable_break_hours?: number
220
		/**
221
		 * Absolute total payable hours
222
		 */
223
		total_payable_hours: number
224
		/**
225
		 * Absolute shift duration hours
226
		 */
227
		shift_duration_hours?: number
228
		[k: string]: unknown
229
	}
230
	/**
231
	 * Type of the shift
232
	 */
233
	shift_type: 'CORRECTION_ABSOLUTE'
234
	/**
235
	 * Description of the correction shift.
236
	 */
237
	description: string
238
	/**
239
	 * External ID of the correction shift.
240
	 */
241
	external_id: string
242
	payroll_cycle_ref?: {
243
		/**
244
		 * Date in ISO 8601 format that helps referencing a payroll cycle
245
		 */
246
		date: string
247
		[k: string]: unknown
248
	}
249
	/**
250
	 * External ID of the original shift being corrected
251
	 */
252
	shift_reference_id: string
253
	[k: string]: unknown
254
}
255
export interface CorrectionDeltaShiftNOTRECOMMENDEDLEGACY {
256
	/**
257
	 * Type of the shift
258
	 */
259
	shift_type: 'CORRECTION_DELTA'
260
	corrections: {
261
		/**
262
		 * Type of correction
263
		 */
264
		type: string
265
		/**
266
		 * Break hours to add or subtract
267
		 */
268
		total_break_hours?: number
269
		/**
270
		 * Payable break hours to add or subtract
271
		 */
272
		payable_break_hours?: number
273
		/**
274
		 * Payable hours to add or subtract
275
		 */
276
		total_payable_hours?: number
277
		/**
278
		 * Shift duration hours to add or subtract
279
		 */
280
		shift_duration_hours?: number
281
	}[]
282
	/**
283
	 * Description of the correction shift.
284
	 */
285
	description: string
286
	/**
287
	 * External ID of the correction shift.
288
	 */
289
	external_id: string
290
	payroll_cycle_ref?: {
291
		/**
292
		 * Date in ISO 8601 format that helps referencing a payroll cycle
293
		 */
294
		date: string
295
		[k: string]: unknown
296
	}
297
	/**
298
	 * External ID of the original shift being corrected
299
	 */
300
	shift_reference_id: string
301
	[k: string]: unknown
302
}
303