0

Get Assessment Packages

by
Published Oct 17, 2025

> 🚧 Partner Restricted > All assessment API endpoints are restricted to assessment providers that have signed a Paylocity technology partnership agreement.

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 Assessment Packages
8
 * > 🚧 Partner Restricted
9
> All assessment API endpoints are restricted to assessment providers that have signed a Paylocity technology partnership agreement.
10
 */
11
export async function main(
12
	auth: Paylocity,
13
	companyId: string,
14
	offset: string | undefined,
15
	limit: string | undefined,
16
	includeTotalCount: string | undefined,
17
	testMode?: string
18
) {
19
	const url = new URL(
20
		`https://dc1prodgwext.paylocity.com/apiHub/performanceManagement/v1/companies/${companyId}/assessmentPackages`
21
	)
22
	for (const [k, v] of [
23
		['offset', offset],
24
		['limit', limit],
25
		['includeTotalCount', includeTotalCount]
26
	]) {
27
		if (v !== undefined && v !== '' && k !== undefined) {
28
			url.searchParams.append(k, v)
29
		}
30
	}
31
	const response = await fetch(url, {
32
		method: 'GET',
33
		headers: {
34
			...(testMode ? { testMode: testMode } : {}),
35
			Authorization:
36
				'Bearer ' +
37
				(await getOAuthToken(auth, 'https://dc1prodgwext.paylocity.com/public/security/v1/token'))
38
		},
39
		body: undefined
40
	})
41
	if (!response.ok) {
42
		const text = await response.text()
43
		throw new Error(`${response.status} ${text}`)
44
	}
45
	return await response.json()
46
}
47

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

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

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

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