0

Get employee pay statement details data for the specified year.

by
Published Oct 17, 2025

Get pay statement details API will return employee pay statement details data currently available in Paylocity Payroll/HR solution for the specified year.

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 employee pay statement details data for the specified year.
8
 * Get pay statement details API will return employee pay statement details data currently available in Paylocity Payroll/HR solution for the specified year.
9
 */
10
export async function main(
11
	auth: Paylocity,
12
	companyId: string,
13
	employeeId: string,
14
	year: string,
15
	pagesize: string | undefined,
16
	pagenumber: string | undefined,
17
	includetotalcount: string | undefined,
18
	codegroup: string | undefined
19
) {
20
	const url = new URL(
21
		`https://dc1prodgwext.paylocity.com/api/v2/companies/${companyId}/employees/${employeeId}/paystatement/details/${year}`
22
	)
23
	for (const [k, v] of [
24
		['pagesize', pagesize],
25
		['pagenumber', pagenumber],
26
		['includetotalcount', includetotalcount],
27
		['codegroup', codegroup]
28
	]) {
29
		if (v !== undefined && v !== '' && k !== undefined) {
30
			url.searchParams.append(k, v)
31
		}
32
	}
33
	const response = await fetch(url, {
34
		method: 'GET',
35
		headers: {
36
			Authorization:
37
				'Bearer ' +
38
				(await getOAuthToken(auth, 'https://dc1prodgwext.paylocity.com/public/security/v1/token'))
39
		},
40
		body: undefined
41
	})
42
	if (!response.ok) {
43
		const text = await response.text()
44
		throw new Error(`${response.status} ${text}`)
45
	}
46
	return await response.json()
47
}
48

49
async function getOAuthToken(auth: Paylocity, tokenUrl: string): Promise<string> {
50
	const params = new URLSearchParams({
51
		grant_type: 'client_credentials',
52
		client_id: auth.clientId,
53
		client_secret: auth.clientSecret
54
	})
55

56
	const response = await fetch(tokenUrl, {
57
		method: 'POST',
58
		headers: {
59
			Authorization: 'Basic ' + btoa(`${auth.clientId}:${auth.clientSecret}`),
60
			'Content-Type': 'application/x-www-form-urlencoded'
61
		},
62
		body: params.toString()
63
	})
64

65
	if (!response.ok) {
66
		const text = await response.text()
67
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
68
	}
69

70
	const data = await response.json()
71
	return data.access_token
72
}
73