0

Get Screening Packages

by
Published Oct 17, 2025

> 🚧 Partner Restricted > All background check API endpoints are restricted to background check 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 Screening Packages
8
 * > 🚧 Partner Restricted
9
> All background check API endpoints are restricted to background check providers that have signed a Paylocity technology partnership agreement.
10
 */
11
export async function main(auth: Paylocity, companyId: string, testMode?: string) {
12
	const url = new URL(
13
		`https://dc1prodgwext.paylocity.com/compliance/v1/companies/${companyId}/backgroundCheck/screeningPackages`
14
	)
15

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

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

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

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

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