0

Company Custom Employment Types

by
Published Oct 17, 2025

Array of custom employment types thata worker could be assigned to.

Script paychex Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Company Custom Employment Types
4
 * Array of custom employment types thata worker could be assigned to.
5
 */
6
export async function main(auth: RT.Paychex, companyId: string) {
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}/customemploymenttypes`)
9

10
	const response = await fetch(url, {
11
		method: 'GET',
12
		headers: {
13
			Authorization: 'Bearer ' + accessToken
14
		},
15
		body: undefined
16
	})
17
	if (!response.ok) {
18
		const text = await response.text()
19
		throw new Error(`${response.status} ${text}`)
20
	}
21
	return await response.json()
22
}
23

24
async function getOAuthToken(auth: RT.Paychex, tokenUrl: string): Promise<string> {
25
	const params = new URLSearchParams({
26
		grant_type: 'client_credentials'
27
	})
28

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

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

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