0

Get Pay Frequency Codes

by
Published Oct 17, 2025

**Summary Description** The GET Pay Frequency Code by list by Company ID endpoint allows users to retrieve a comprehensive list of Pay Frequency Code details from a client's Paylocity instance.

Script paylocity Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Paylocity = {
3
	clientId: string
4
	clientSecret: string
5
}
6
/**
7
 * Get Pay Frequency Codes
8
 * **Summary Description**
9

10
The GET Pay Frequency Code by list by Company ID endpoint allows users to retrieve a comprehensive list of Pay Frequency Code details from a client's Paylocity instance.
11
 */
12
export async function main(auth: Paylocity, companyId: string, testMode?: string) {
13
	const url = new URL(
14
		`https://dc1prodgwext.paylocity.com/apiHub/payroll/v1/companies/${companyId}/payFrequencies`
15
	)
16

17
	const response = await fetch(url, {
18
		method: 'GET',
19
		headers: {
20
			...(testMode ? { testMode: testMode } : {}),
21
			Authorization:
22
				'Bearer ' +
23
				(await getOAuthToken(auth, 'https://dc1prodgwext.paylocity.com/public/security/v1/token'))
24
		},
25
		body: undefined
26
	})
27
	if (!response.ok) {
28
		const text = await response.text()
29
		throw new Error(`${response.status} ${text}`)
30
	}
31
	return await response.json()
32
}
33

34
async function getOAuthToken(auth: Paylocity, tokenUrl: string): Promise<string> {
35
	const params = new URLSearchParams({
36
		grant_type: 'client_credentials',
37
		client_id: auth.clientId,
38
		client_secret: auth.clientSecret
39
	})
40

41
	const response = await fetch(tokenUrl, {
42
		method: 'POST',
43
		headers: {
44
			Authorization: 'Basic ' + btoa(`${auth.clientId}:${auth.clientSecret}`),
45
			'Content-Type': 'application/x-www-form-urlencoded'
46
		},
47
		body: params.toString()
48
	})
49

50
	if (!response.ok) {
51
		const text = await response.text()
52
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
53
	}
54

55
	const data = await response.json()
56
	return data.access_token
57
}
58