0

Create Webhook for Candidate Screening Order

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. Please reach out to [email protected] if you would like to discuss partnership opportunities. **Summary Description** Register the webhook URL for the subscription of new CandidateScreeningOrder **Use Cases** - Partner provides the webhook URL for new candidate orders

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
 * Create Webhook for Candidate Screening Order
8
 * > 🚧 Partner Restricted
9
> All background check API endpoints are restricted to background check providers that have signed a Paylocity technology partnership agreement. Please reach out to Techpartnerships@paylocity.com if you would like to discuss partnership opportunities.
10

11
**Summary Description**
12

13
Register the webhook URL for the subscription of new CandidateScreeningOrder
14

15
**Use Cases**
16

17
- Partner provides the webhook URL for new candidate orders
18

19
 */
20
export async function main(
21
	auth: Paylocity,
22
	body: {
23
		apiKey?: string
24
		callbackDetails?: {
25
			successCallbackUrl?: string
26
			errorCallbackUrl?: string
27
		}
28
		callerDetails?: { callerName?: string }
29
	},
30
	testMode?: string
31
) {
32
	const url = new URL(
33
		`https://dc1prodgwext.paylocity.com/compliance/v1/companies/b6001/backgroundCheck/candidateScreeningOrders/subscription`
34
	)
35

36
	const response = await fetch(url, {
37
		method: 'POST',
38
		headers: {
39
			...(testMode ? { testMode: testMode } : {}),
40
			'Content-Type': 'application/json',
41
			Authorization:
42
				'Bearer ' +
43
				(await getOAuthToken(auth, 'https://dc1prodgwext.paylocity.com/public/security/v1/token'))
44
		},
45
		body: JSON.stringify(body)
46
	})
47
	if (!response.ok) {
48
		const text = await response.text()
49
		throw new Error(`${response.status} ${text}`)
50
	}
51
	return await response.json()
52
}
53

54
async function getOAuthToken(auth: Paylocity, tokenUrl: string): Promise<string> {
55
	const params = new URLSearchParams({
56
		grant_type: 'client_credentials',
57
		client_id: auth.clientId,
58
		client_secret: auth.clientSecret
59
	})
60

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

70
	if (!response.ok) {
71
		const text = await response.text()
72
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
73
	}
74

75
	const data = await response.json()
76
	return data.access_token
77
}
78