1 | |
2 | type Paylocity = { |
3 | clientId: string |
4 | clientSecret: string |
5 | } |
6 | |
7 | * Update Screening Order Status |
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( |
12 | auth: Paylocity, |
13 | companyId: string, |
14 | body: { |
15 | candidateScreeningOrderId?: string |
16 | updatedAt?: string |
17 | oldStatus?: |
18 | | 'Ordered' |
19 | | 'WaitingOnCandidate' |
20 | | 'InProgress' |
21 | | 'Hold' |
22 | | 'Complete' |
23 | | 'CompleteWithCancelled' |
24 | | 'Cancelled' |
25 | | 'CompleteNeedsReview' |
26 | | 'CompleteNotEligible' |
27 | | 'Suspended' |
28 | | 'Resumed' |
29 | | 'CompleteDisputed' |
30 | | 'InvitationExpired' |
31 | | 'InvitationCancelled' |
32 | | 'PreAdverseActionSent' |
33 | | 'AdverseActionCancelled' |
34 | | 'Dispute' |
35 | | 'AdverseActionSent' |
36 | newStatus?: |
37 | | 'Ordered' |
38 | | 'WaitingOnCandidate' |
39 | | 'InProgress' |
40 | | 'Hold' |
41 | | 'Complete' |
42 | | 'CompleteWithCancelled' |
43 | | 'Cancelled' |
44 | | 'CompleteNeedsReview' |
45 | | 'CompleteNotEligible' |
46 | | 'Suspended' |
47 | | 'Resumed' |
48 | | 'CompleteDisputed' |
49 | | 'InvitationExpired' |
50 | | 'InvitationCancelled' |
51 | | 'PreAdverseActionSent' |
52 | | 'AdverseActionCancelled' |
53 | | 'Dispute' |
54 | | 'AdverseActionSent' |
55 | services?: { |
56 | serviceName?: string |
57 | oldStatus?: |
58 | | 'InProgress' |
59 | | 'Cancelled' |
60 | | 'Suspended' |
61 | | 'Pending' |
62 | | 'Completed' |
63 | | 'Disputed' |
64 | | 'Expired' |
65 | | 'NeedsReview' |
66 | | 'NotEligible' |
67 | newStatus?: |
68 | | 'InProgress' |
69 | | 'Cancelled' |
70 | | 'Suspended' |
71 | | 'Pending' |
72 | | 'Completed' |
73 | | 'Disputed' |
74 | | 'Expired' |
75 | | 'NeedsReview' |
76 | | 'NotEligible' |
77 | note?: string |
78 | }[] |
79 | screeningReportDocuments?: string[] |
80 | } |
81 | ) { |
82 | const url = new URL( |
83 | `https://dc1prodgwext.paylocity.com/compliance/v1/companies/${companyId}/backgroundCheck/candidateScreeningOrders/status` |
84 | ) |
85 |
|
86 | const response = await fetch(url, { |
87 | method: 'PATCH', |
88 | headers: { |
89 | 'Content-Type': 'application/json', |
90 | Authorization: |
91 | 'Bearer ' + |
92 | (await getOAuthToken(auth, 'https://dc1prodgwext.paylocity.com/public/security/v1/token')) |
93 | }, |
94 | body: JSON.stringify(body) |
95 | }) |
96 | if (!response.ok) { |
97 | const text = await response.text() |
98 | throw new Error(`${response.status} ${text}`) |
99 | } |
100 | return await response.json() |
101 | } |
102 |
|
103 | async function getOAuthToken(auth: Paylocity, tokenUrl: string): Promise<string> { |
104 | const params = new URLSearchParams({ |
105 | grant_type: 'client_credentials', |
106 | client_id: auth.clientId, |
107 | client_secret: auth.clientSecret |
108 | }) |
109 |
|
110 | const response = await fetch(tokenUrl, { |
111 | method: 'POST', |
112 | headers: { |
113 | Authorization: 'Basic ' + btoa(`${auth.clientId}:${auth.clientSecret}`), |
114 | 'Content-Type': 'application/x-www-form-urlencoded' |
115 | }, |
116 | body: params.toString() |
117 | }) |
118 |
|
119 | if (!response.ok) { |
120 | const text = await response.text() |
121 | throw new Error(`OAuth token request failed: ${response.status} ${text}`) |
122 | } |
123 |
|
124 | const data = await response.json() |
125 | return data.access_token |
126 | } |
127 |
|