0

Company Pay Frequencies

by
Published Oct 17, 2025

Array of pay frequencies that workers maybe paid on. This is a generic array that is currently not specific to the companies pay frequency. This is to be used with the workers pay components to determine what the frequency, occurrence, and intervals are allowed.

Script paychex Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Company Pay Frequencies
4
 * Array of pay frequencies that workers maybe paid on. This is a generic array that is currently not specific to the companies pay frequency. This is to be used with the workers pay components to determine what the frequency, occurrence, and intervals are allowed.
5
 */
6
export async function main(auth: RT.Paychex, companyId: string, payfrequency?: string | undefined) {
7
	const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token')
8
	const url = new URL(`https://api.paychex.com/companies/${companyId}/payfrequencies`)
9
	for (const [k, v] of [['payfrequency', payfrequency]]) {
10
		if (v !== undefined && v !== '') {
11
			url.searchParams.append(k, v)
12
		}
13
	}
14
	const response = await fetch(url, {
15
		method: 'GET',
16
		headers: {
17
			Authorization: 'Bearer ' + accessToken
18
		},
19
		body: undefined
20
	})
21
	if (!response.ok) {
22
		const text = await response.text()
23
		throw new Error(`${response.status} ${text}`)
24
	}
25
	return await response.json()
26
}
27

28
async function getOAuthToken(auth: RT.Paychex, tokenUrl: string): Promise<string> {
29
	const params = new URLSearchParams({
30
		grant_type: 'client_credentials'
31
	})
32

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

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

47
	const data = await response.json()
48
	return data.access_token
49
}
50