0

Worker

by
Published Oct 17, 2025

Update a unique worker (employee and contractor) that your application has been granted access to modify.

Script paychex Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Worker
4
 * Update a unique worker (employee and contractor) that your application has been granted access to modify.
5
 */
6
export async function main(auth: RT.Paychex, workerId: string, body: Body) {
7
	const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token')
8
	const url = new URL(`https://api.paychex.com/workers/${workerId}`)
9

10
	const response = await fetch(url, {
11
		method: 'PATCH',
12
		headers: {
13
			'Content-Type': 'application/json',
14
			Authorization: 'Bearer ' + accessToken
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
async function getOAuthToken(auth: RT.Paychex, tokenUrl: string): Promise<string> {
26
	const params = new URLSearchParams({
27
		grant_type: 'client_credentials'
28
	})
29

30
	const response = await fetch(tokenUrl, {
31
		method: 'POST',
32
		headers: {
33
			Authorization: 'Basic ' + btoa(`${auth.client_id}:${auth.client_secret}`),
34
			'Content-Type': 'application/x-www-form-urlencoded'
35
		},
36
		body: params.toString()
37
	})
38

39
	if (!response.ok) {
40
		const text = await response.text()
41
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
42
	}
43

44
	const data = await response.json()
45
	return data.access_token
46
}
47

48
/* eslint-disable */
49
/**
50
 * This file was automatically generated by json-schema-to-typescript.
51
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
52
 * and run json-schema-to-typescript to regenerate this file.
53
 */
54

55
export interface Body {
56
	/**
57
	 * The unique identifier associated with this worker representation.
58
	 */
59
	workerId?: string
60
	/**
61
	 * The workers employee identification information.
62
	 */
63
	employeeId?: string
64
	/**
65
	 * The type of worker. This data field cannot be PATCHED.NOTE: An IN_PROGRESS worker cannot be POSTED with a value of CONTRACTOR.
66
	 */
67
	workerType?: 'EMPLOYEE' | 'CONTRACTOR' | 'INDEPENDENT_CONTRACTOR'
68
	/**
69
	 * The type of employment for the worker.
70
	 */
71
	employmentType?: 'FULL_TIME' | 'PART_TIME'
72
	/**
73
	 * The workers custom employment type
74
	 */
75
	customEmploymentType?: {
76
		/**
77
		 * Unique ID for the custom employment type which the worker is assigned to. This data field cannot be PATCHED for IN_PROGRESS workers.
78
		 */
79
		customEmploymentTypeId?: string
80
		/**
81
		 * The name of the custom employment type that the worker is assigned to.
82
		 */
83
		customEmploymentTypeName?: string
84
		[k: string]: unknown
85
	}
86
	/**
87
	 * The Overtime classification of the worker. This data field cannot be PATCHED for ACTIVE workers.
88
	 */
89
	exemptionType?: 'EXEMPT' | 'NON_EXEMPT'
90
	/**
91
	 * The state(s) in which the worker works in.
92
	 */
93
	workState?: string
94
	/**
95
	 * The workers date of birth. It cannot be greater than today's date.
96
	 */
97
	birthDate?: string
98
	sex?: 'MALE' | 'FEMALE' | 'NOT_SPECIFIED'
99
	/**
100
	 * Disclaimer:This parameter is not visible in Flex for the client. This data field cannot be PATCHED for ACTIVE workers.
101
	 */
102
	ethnicityCode?: string
103
	/**
104
	 * The date which the worker was hired. It cannot be PATCHED for ACTIVE workers.
105
	 */
106
	hireDate?: string
107
	/**
108
	 * The clock ID of the worker that can be an identification for other systems.
109
	 */
110
	clockId?: string
111
	/**
112
	 * Information about the workers name.
113
	 */
114
	name?: {
115
		/**
116
		 * The family or last name of a worker.
117
		 */
118
		familyName?: string
119
		/**
120
		 * A subordinate given name, or initial representing that name, of a worker. <br />NOTE:  Please send in just a single character initial for middleName.  <br />If sending in more than one character the name will be truncated the first letter of the middleName. <br /> A full middle name can be entered directly in Paychex Flex only at this time.
121
		 */
122
		middleName?: string
123
		/**
124
		 * The given or first name of a worker. For an independent contractor that is a company rather than an individual, the name of the company.
125
		 */
126
		givenName?: string
127
		/**
128
		 * The first name that the worker prefers to go by
129
		 */
130
		preferredName?: string
131
		/**
132
		 * The last name that the worker prefers to go by
133
		 */
134
		preferredLastName?: string
135
		/**
136
		 * The pronoun that the worker prefers to go by. This data field cannot be POSTED.
137
		 */
138
		pronoun?: string
139
		/**
140
		 * A qualifier to the name of a worker, indicating generation.
141
		 */
142
		qualificationAffixCode?: string
143
		/**
144
		 * A personal title that comes before an individual's name in a formal address (such as Dr., Prof., Rev., Mr.).
145
		 */
146
		titleAffixCode?: string
147
		[k: string]: unknown
148
	}
149
	/**
150
	 * The workers seniority date. This data field cannot be POSTED or PATCHED.
151
	 */
152
	seniorityDate?: string
153
	/**
154
	 * The workers profile image url. This data field cannot be POSTED or PATCHED.
155
	 */
156
	profileImageURL?: string
157
	/**
158
	 * The workers legal tax identification information. This data field cannot be PATCHED for ACTIVE workers.
159
	 */
160
	legalId?: {
161
		/**
162
		 * A value that identifies the type of taxpayer identification number provided.   SSN: Social  Security Number - 9 digit number   , FEIN: Federal Employer Identification Number (EIN)
163
		 */
164
		legalIdType?: 'SSN' | 'FEIN'
165
		/**
166
		 * The federal level taxpayer id number that the worker has provided
167
		 */
168
		legalIdValue?: string
169
		[k: string]: unknown
170
	}
171
	/**
172
	 * The workers home labor assignment.
173
	 */
174
	laborAssignmentId?: string
175
	/**
176
	 * The workers location.
177
	 */
178
	locationId?: string
179
	/**
180
	 * The workers home job
181
	 */
182
	jobId?: string
183
	/**
184
	 * The workers current job/position information.
185
	 */
186
	job?: {
187
		/**
188
		 * Unique ID for that job within the company that the worker is assigned to.
189
		 */
190
		jobTitleId?: string
191
		/**
192
		 * The name of the title that the worker is assigned to.
193
		 */
194
		title?: string
195
		[k: string]: unknown
196
	}
197
	/**
198
	 * The organization which the worker is part of.
199
	 */
200
	organization?: {
201
		/**
202
		 * The unique identifier associated with this organizations representation.
203
		 */
204
		organizationId?: string
205
		/**
206
		 * The name of the organization.
207
		 */
208
		name?: string
209
		/**
210
		 * The number assigned to the organization.
211
		 */
212
		number?: string
213
		/**
214
		 * The level number within the organizational structures hierarchy.
215
		 */
216
		level?: string
217
		links?: {
218
			rel?: string
219
			href?: string
220
			hreflang?: string
221
			media?: string
222
			title?: string
223
			type?: string
224
			deprecation?: string
225
			profile?: string
226
			name?: string
227
			[k: string]: unknown
228
		}[]
229
		[k: string]: unknown
230
	}
231
	/**
232
	 * The workers supervisor information. Supervisor cannot be a TERMINATED or IN_PROGRESS worker.
233
	 */
234
	supervisor?: {
235
		/**
236
		 * The supervisor's Id
237
		 */
238
		workerId?: string
239
		/**
240
		 * Information about the workers name.
241
		 */
242
		name?: {
243
			/**
244
			 * The family or last name of a worker.
245
			 */
246
			familyName?: string
247
			/**
248
			 * A subordinate given name, or initial representing that name, of a worker. <br />NOTE:  Please send in just a single character initial for middleName.  <br />If sending in more than one character the name will be truncated the first letter of the middleName. <br /> A full middle name can be entered directly in Paychex Flex only at this time.
249
			 */
250
			middleName?: string
251
			/**
252
			 * The given or first name of a worker. For an independent contractor that is a company rather than an individual, the name of the company.
253
			 */
254
			givenName?: string
255
			/**
256
			 * The first name that the worker prefers to go by
257
			 */
258
			preferredName?: string
259
			/**
260
			 * The last name that the worker prefers to go by
261
			 */
262
			preferredLastName?: string
263
			/**
264
			 * The pronoun that the worker prefers to go by. This data field cannot be POSTED.
265
			 */
266
			pronoun?: string
267
			/**
268
			 * A qualifier to the name of a worker, indicating generation.
269
			 */
270
			qualificationAffixCode?: string
271
			/**
272
			 * A personal title that comes before an individual's name in a formal address (such as Dr., Prof., Rev., Mr.).
273
			 */
274
			titleAffixCode?: string
275
			[k: string]: unknown
276
		}
277
		[k: string]: unknown
278
	}
279
	/**
280
	 * The workers employment status information. This data field cannot be POSTED or PATCHED for an IN_PROGRESS worker.
281
	 */
282
	currentStatus?: {
283
		/**
284
		 * The unique identifier associated with this status representation.
285
		 */
286
		workerStatusId?: string
287
		/**
288
		 * The workers current status.
289
		 */
290
		statusType?: 'ACTIVE' | 'INACTIVE' | 'TERMINATED' | 'PENDING' | 'IN_PROGRESS'
291
		/**
292
		 * The detailed reason of the workers current status.
293
		 */
294
		statusReason?: string
295
		/**
296
		 * Date that this status has started for the worker.
297
		 */
298
		effectiveDate?: string
299
		order?: number
300
		links?: {
301
			rel?: string
302
			href?: string
303
			hreflang?: string
304
			media?: string
305
			title?: string
306
			type?: string
307
			deprecation?: string
308
			profile?: string
309
			name?: string
310
			[k: string]: unknown
311
		}[]
312
		[k: string]: unknown
313
	}
314
	/**
315
	 * Worker Communications. This data field cannot be updated for worker endpoint.
316
	 */
317
	communications?: {
318
		/**
319
		 * The ID for the workers specific communication item.
320
		 */
321
		communicationId?: string
322
		/**
323
		 * A set of communication types classifying an instruction that the customer, requester, or subject must comply with in order for the screening to go forward. NOTE: PHONE and EMAIL type supports BUSINESS and PERSONAL usage type only.MOBILE_PHONE, FAX and PAGER supports BUSINESS usage type only.This data field cannot be PATCHED.
324
		 */
325
		type?:
326
			| 'STREET_ADDRESS'
327
			| 'PO_BOX_ADDRESS'
328
			| 'PHONE'
329
			| 'MOBILE_PHONE'
330
			| 'FAX'
331
			| 'EMAIL'
332
			| 'PAGER'
333
		/**
334
		 * A code classifying a designated use associated with a contact method. For example, whether a telephone or email address is one for business communications or one primarily for personal use.This data field cannot be PATCHED.
335
		 */
336
		usageType?:
337
			| 'PERSONAL'
338
			| 'BUSINESS'
339
			| 'HOME'
340
			| 'WORK'
341
			| 'LOCATION_STREET_ADDRESS'
342
			| 'MAILING_ADDRESS'
343
		/**
344
		 * The country dialing code for a communication number
345
		 */
346
		dialCountry?: string
347
		/**
348
		 * The area dialing code for a communication number
349
		 */
350
		dialArea?: string
351
		/**
352
		 * The communication number, not including country dialing or area dialing codes
353
		 */
354
		dialNumber?: string
355
		/**
356
		 * The extension of the associated communication number
357
		 */
358
		dialExtension?: string
359
		/**
360
		 * The mailto address as specified in RFC2368
361
		 */
362
		uri?: string
363
		/**
364
		 * The street address line one
365
		 */
366
		streetLineOne?: string
367
		/**
368
		 * The street address line two
369
		 */
370
		streetLineTwo?: string
371
		/**
372
		 * The postal office box. This data field cannot be PATCHED
373
		 */
374
		postOfficeBox?: string
375
		/**
376
		 * The city name
377
		 */
378
		city?: string
379
		/**
380
		 * The zip-code
381
		 */
382
		postalCode?: string
383
		/**
384
		 * The zip-code extension
385
		 */
386
		postalCodeExtension?: string
387
		/**
388
		 * The state code (ISO 3166 subdivision code)
389
		 */
390
		countrySubdivisionCode?: string
391
		/**
392
		 * The country code (ISO 3166 alpha-2)
393
		 */
394
		countryCode?: string
395
		links?: {
396
			rel?: string
397
			href?: string
398
			hreflang?: string
399
			media?: string
400
			title?: string
401
			type?: string
402
			deprecation?: string
403
			profile?: string
404
			name?: string
405
			[k: string]: unknown
406
		}[]
407
		[k: string]: unknown
408
	}[]
409
	links?: {
410
		rel?: string
411
		href?: string
412
		hreflang?: string
413
		media?: string
414
		title?: string
415
		type?: string
416
		deprecation?: string
417
		profile?: string
418
		name?: string
419
		[k: string]: unknown
420
	}[]
421
	/**
422
	 * Id that you define which is used for error handling/responses.This data field is used while POSTING multiple IN_PROGRESS workers
423
	 */
424
	workerCorrelationId?: string
425
	[k: string]: unknown
426
}
427