0

Company Checks

by
Published Oct 17, 2025

Get check(s) that are for a specific company within a processed or unprocessed pay period.

Script paychex Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Company Checks
4
 * Get check(s) that are for a specific company within a processed or unprocessed pay period.
5
 */
6
export async function main(
7
	auth: RT.Paychex,
8
	companyId: string,
9
	payperiodid: string | undefined,
10
	offset?: string | undefined,
11
	limit?: string | undefined,
12
	filterbyuserid?: string | undefined
13
) {
14
	const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token')
15
	const url = new URL(`https://api.paychex.com/companies/${companyId}/checks`)
16
	for (const [k, v] of [
17
		['payperiodid', payperiodid],
18
		['offset', offset],
19
		['limit', limit],
20
		['filterbyuserid', filterbyuserid]
21
	]) {
22
		if (v !== undefined && v !== '') {
23
			url.searchParams.append(k, v)
24
		}
25
	}
26
	const response = await fetch(url, {
27
		method: 'GET',
28
		headers: {
29
			Authorization: 'Bearer ' + accessToken
30
		},
31
		body: undefined
32
	})
33
	if (!response.ok) {
34
		const text = await response.text()
35
		throw new Error(`${response.status} ${text}`)
36
	}
37
	return await response.json()
38
}
39

40
async function getOAuthToken(auth: RT.Paychex, tokenUrl: string): Promise<string> {
41
	const params = new URLSearchParams({
42
		grant_type: 'client_credentials'
43
	})
44

45
	const response = await fetch(tokenUrl, {
46
		method: 'POST',
47
		headers: {
48
			Authorization: 'Basic ' + btoa(`${auth.client_id}:${auth.client_secret}`),
49
			'Content-Type': 'application/x-www-form-urlencoded'
50
		},
51
		body: params.toString()
52
	})
53

54
	if (!response.ok) {
55
		const text = await response.text()
56
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
57
	}
58

59
	const data = await response.json()
60
	return data.access_token
61
}
62