0

Worker CustomField

by
Published Oct 17, 2025

Update CustomField at the worker level

Script paychex Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Worker CustomField
4
 * Update CustomField at the worker level
5
 */
6
export async function main(
7
	auth: RT.Paychex,
8
	workerId: string,
9
	workerCustomFieldId: string,
10
	body: Body
11
) {
12
	const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token')
13
	const url = new URL(
14
		`https://api.paychex.com/workers/${workerId}/customfields/${workerCustomFieldId}`
15
	)
16

17
	const response = await fetch(url, {
18
		method: 'PATCH',
19
		headers: {
20
			'Content-Type': 'application/json',
21
			Authorization: 'Bearer ' + accessToken
22
		},
23
		body: JSON.stringify(body)
24
	})
25
	if (!response.ok) {
26
		const text = await response.text()
27
		throw new Error(`${response.status} ${text}`)
28
	}
29
	return await response.json()
30
}
31

32
async function getOAuthToken(auth: RT.Paychex, tokenUrl: string): Promise<string> {
33
	const params = new URLSearchParams({
34
		grant_type: 'client_credentials'
35
	})
36

37
	const response = await fetch(tokenUrl, {
38
		method: 'POST',
39
		headers: {
40
			Authorization: 'Basic ' + btoa(`${auth.client_id}:${auth.client_secret}`),
41
			'Content-Type': 'application/x-www-form-urlencoded'
42
		},
43
		body: params.toString()
44
	})
45

46
	if (!response.ok) {
47
		const text = await response.text()
48
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
49
	}
50

51
	const data = await response.json()
52
	return data.access_token
53
}
54

55
/* eslint-disable */
56
/**
57
 * This file was automatically generated by json-schema-to-typescript.
58
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
59
 * and run json-schema-to-typescript to regenerate this file.
60
 */
61

62
export interface Body {
63
	/**
64
	 * The unique identifier that is autogenerated when a custom field is created
65
	 */
66
	workerCustomFieldId?: string
67
	/**
68
	 * client Custom Field Id
69
	 */
70
	customFieldId?: string
71
	/**
72
	 * The type of field the custom field is
73
	 */
74
	type?: 'DROPDOWN' | 'TEXT' | 'BOOLEAN' | 'DATE' | 'NUMERIC, NUMERIC__0_00_ OR NUMERIC__0_0000_'
75
	/**
76
	 * The value for BOOLEAN type (true/false)
77
	 */
78
	booleanValue?: boolean
79
	/**
80
	 * The value for TEXT type (any text, alphanumeric, special characters allowed)
81
	 */
82
	textValue?: string
83
	/**
84
	 * Numeric data type can have three formats namely - whole number, second decimal place and fourth decimal place, example: 12 , 12.34 or 12.3456
85
	 */
86
	numericValue?: number
87
	/**
88
	 * The value for DATE type , example : 2012-02-01T05:00:00Z
89
	 */
90
	dateValue?: string
91
	/**
92
	 * The unique identifier that is autogenerated when dropdown list is created
93
	 */
94
	dropdownId?: string
95
	/**
96
	 * The value for dropdown list
97
	 */
98
	dropdownValue?: string
99
	/**
100
	 * The name of the custom field. Such as: "Hobbies"
101
	 */
102
	customFieldName?: string
103
	/**
104
	 * Where to indicate if the custom field is required on the worker where true = required and false = not required
105
	 */
106
	required?: boolean
107
	/**
108
	 * Where to indicate if the custom field is required on the workers pay stub, where true = required and false = not required.
109
	 */
110
	checkStub?: boolean
111
	/**
112
	 * Where to indicate if the custom field is able to be edited by the employee, where true = required and false = not required.
113
	 */
114
	employeeEditable?: boolean
115
	[k: string]: unknown
116
}
117