0

Company Worker Status

by
Published Oct 17, 2025

Information about a single status.

Script paychex Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Company Worker Status
4
 * Information about a single status.
5
 */
6
export async function main(auth: RT.Paychex, companyId: string, workerStatusId: string) {
7
	const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token')
8
	const url = new URL(
9
		`https://api.paychex.com/companies/${companyId}/workerstatuses/${workerStatusId}`
10
	)
11

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

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

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

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

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