0

Update Assessment Order

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
 * Update Assessment Order
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
	orderId: string,
15
	body: {
16
		partnerTrackingId?: string
17
		overallScore?: string
18
		overallScoreDescription?: string
19
		overallReports?: { name?: string; url?: string }[]
20
		assessments?: {
21
			assessmentId?: string
22
			assessmentStatus?: {
23
				updatedAt?: string
24
				value?:
25
					| 'Ordered'
26
					| 'WaitingOnAssessee'
27
					| 'InProgress'
28
					| 'Hold'
29
					| 'Complete'
30
					| 'CompleteReview'
31
					| 'RetestRecommended'
32
					| 'Expired'
33
			}
34
			assessmentResults?: {
35
				tests?: {
36
					id?: string
37
					score?: {
38
						value?: string
39
						description?: string
40
						attempt?: number
41
						reports?: { name?: string; url?: string }[]
42
					}
43
					testStatus?: {
44
						updatedAt?: string
45
						value?:
46
							| 'Ordered'
47
							| 'InProgress'
48
							| 'Hold'
49
							| 'Complete'
50
							| 'RetestRecommended'
51
							| 'Expired'
52
							| 'Pending'
53
					}
54
				}[]
55
				score?: string
56
				scoreDescription?: string
57
				reports?: { name?: string; url?: string }[]
58
			}
59
		}[]
60
	},
61
	testMode?: string
62
) {
63
	const url = new URL(
64
		`https://dc1prodgwext.paylocity.com/apiHub/performanceManagement/v1/companies/${companyId}/assessmentOrders/${orderId}`
65
	)
66

67
	const response = await fetch(url, {
68
		method: 'PATCH',
69
		headers: {
70
			...(testMode ? { testMode: testMode } : {}),
71
			'Content-Type': 'application/json',
72
			Authorization:
73
				'Bearer ' +
74
				(await getOAuthToken(auth, 'https://dc1prodgwext.paylocity.com/public/security/v1/token'))
75
		},
76
		body: JSON.stringify(body)
77
	})
78
	if (!response.ok) {
79
		const text = await response.text()
80
		throw new Error(`${response.status} ${text}`)
81
	}
82
	return await response.text()
83
}
84

85
async function getOAuthToken(auth: Paylocity, tokenUrl: string): Promise<string> {
86
	const params = new URLSearchParams({
87
		grant_type: 'client_credentials',
88
		client_id: auth.clientId,
89
		client_secret: auth.clientSecret
90
	})
91

92
	const response = await fetch(tokenUrl, {
93
		method: 'POST',
94
		headers: {
95
			Authorization: 'Basic ' + btoa(`${auth.clientId}:${auth.clientSecret}`),
96
			'Content-Type': 'application/x-www-form-urlencoded'
97
		},
98
		body: params.toString()
99
	})
100

101
	if (!response.ok) {
102
		const text = await response.text()
103
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
104
	}
105

106
	const data = await response.json()
107
	return data.access_token
108
}
109