//native
type Paylocity = {
clientId: string
clientSecret: string
}
/**
* Update Assessment Order
* > 🚧 Partner Restricted
> All assessment API endpoints are restricted to assessment providers that have signed a Paylocity technology partnership agreement.
*/
export async function main(
auth: Paylocity,
companyId: string,
orderId: string,
body: {
partnerTrackingId?: string
overallScore?: string
overallScoreDescription?: string
overallReports?: { name?: string; url?: string }[]
assessments?: {
assessmentId?: string
assessmentStatus?: {
updatedAt?: string
value?:
| 'Ordered'
| 'WaitingOnAssessee'
| 'InProgress'
| 'Hold'
| 'Complete'
| 'CompleteReview'
| 'RetestRecommended'
| 'Expired'
}
assessmentResults?: {
tests?: {
id?: string
score?: {
value?: string
description?: string
attempt?: number
reports?: { name?: string; url?: string }[]
}
testStatus?: {
updatedAt?: string
value?:
| 'Ordered'
| 'InProgress'
| 'Hold'
| 'Complete'
| 'RetestRecommended'
| 'Expired'
| 'Pending'
}
}[]
score?: string
scoreDescription?: string
reports?: { name?: string; url?: string }[]
}
}[]
},
testMode?: string
) {
const url = new URL(
`https://dc1prodgwext.paylocity.com/apiHub/performanceManagement/v1/companies/${companyId}/assessmentOrders/${orderId}`
)
const response = await fetch(url, {
method: 'PATCH',
headers: {
...(testMode ? { testMode: testMode } : {}),
'Content-Type': 'application/json',
Authorization:
'Bearer ' +
(await getOAuthToken(auth, 'https://dc1prodgwext.paylocity.com/public/security/v1/token'))
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.text()
}
async function getOAuthToken(auth: Paylocity, tokenUrl: string): Promise<string> {
const params = new URLSearchParams({
grant_type: 'client_credentials',
client_id: auth.clientId,
client_secret: auth.clientSecret
})
const response = await fetch(tokenUrl, {
method: 'POST',
headers: {
Authorization: 'Basic ' + btoa(`${auth.clientId}:${auth.clientSecret}`),
'Content-Type': 'application/x-www-form-urlencoded'
},
body: params.toString()
})
if (!response.ok) {
const text = await response.text()
throw new Error(`OAuth token request failed: ${response.status} ${text}`)
}
const data = await response.json()
return data.access_token
}
Submitted by hugo697 235 days ago