0

Worker Pay Rate

by
Published Oct 17, 2025

Update a workers specific compensation rate.

Script paychex Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Worker Pay Rate
4
 * Update a workers specific compensation rate.
5
 */
6
export async function main(auth: RT.Paychex, workerId: string, rateId: 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}/compensation/payrates/${rateId}`)
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
/**
56
 * Worker Pay Rate
57
 */
58
export interface Body {
59
	/**
60
	 * Unique identifier for this workers pay rate. **This ID will change if this is created for an IN_PROGRESS worker that is later completed within Flex**
61
	 */
62
	rateId?: string
63
	/**
64
	 * The date when the pay rate is going to begin.
65
	 */
66
	startDate?: string
67
	/**
68
	 * The number of the rate. A worker can have up to 25 different rates.
69
	 */
70
	rateNumber?: string
71
	/**
72
	 * Type of rate.
73
	 */
74
	rateType?:
75
		| 'ANNUAL_SALARY'
76
		| 'PER_PAY_PERIOD_SALARY'
77
		| 'PIECEWORK_RATE'
78
		| 'DAILY_RATE'
79
		| 'HOURLY_RATE'
80
	/**
81
	 * Describes the rate for the worker. A maximum of 30 characters is allowed.
82
	 */
83
	description?: string
84
	/**
85
	 * The currency amount which this rate is applied.
86
	 */
87
	amount?: string
88
	/**
89
	 * Default standard hours that this rate is used with a pay frequency. This data field is not available for an IN_PROGRESS worker.
90
	 */
91
	standardHours?: string
92
	/**
93
	 * Default over time hours that this rate is used with a pay frequency. This data field is not available for an IN_PROGRESS worker.
94
	 */
95
	standardOvertime?: string
96
	/**
97
	 * If this rate is the default one to apply on the worker. This data field is not available for an IN_PROGRESS worker and is considered RATE_1.
98
	 */
99
	default?: boolean
100
	/**
101
	 * The date when the pay rate becomes effective for the worker (can be used only in POST/PATCH for an active worker).
102
	 */
103
	effectiveDate?: string
104
	links?: {
105
		rel?: string
106
		href?: string
107
		hreflang?: string
108
		media?: string
109
		title?: string
110
		type?: string
111
		deprecation?: string
112
		profile?: string
113
		name?: string
114
		[k: string]: unknown
115
	}[]
116
	[k: string]: unknown
117
}
118