0

Update Recurring Deduction Details for a specific past/present/future deduction

by
Published Oct 17, 2025

**Summary Description** This function will allow the API user to update details for a particular deduction code that occurs in the past/present/future. Garnishments cannot be updated using the Deduction endpoints.

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 Recurring Deduction Details for a specific past/present/future deduction
8
 * **Summary Description**
9

10
This function will allow the API user to update details for a particular deduction code that occurs in the past/present/future. Garnishments cannot be updated using the Deduction endpoints.
11
 */
12
export async function main(
13
	auth: Paylocity,
14
	companyId: string,
15
	employeeId: string,
16
	deductionCode: string,
17
	resourceId: string,
18
	body: {
19
		effectiveFrom?: string
20
		effectiveTo?: string
21
		calculationCode?: string
22
		rate?: number
23
		frequency?: string
24
		agency?: string
25
		arrear?: number
26
		miscellaneousInfo?: string
27
		note?: string
28
		selfInsured?: false | true
29
		priority?: number
30
		loan401K?: {
31
			loanNumber?: string
32
			issueDate?: string
33
			firstPaymentDate?: string
34
		}
35
		costCenters?: { level?: number; code?: string }[]
36
		limits?: {
37
			goal?: number
38
			paidToDate?: number
39
			payPeriodMinimum?: number
40
			payPeriodMaximum?: number
41
			annualMaximum?: number
42
		}
43
	}
44
) {
45
	const url = new URL(
46
		`https://dc1prodgwext.paylocity.com/apiHub/payroll/v1/companies/${companyId}/employees/${employeeId}/deductions/${deductionCode}/${resourceId}`
47
	)
48

49
	const response = await fetch(url, {
50
		method: 'PUT',
51
		headers: {
52
			'Content-Type': 'application/json',
53
			Authorization:
54
				'Bearer ' +
55
				(await getOAuthToken(auth, 'https://dc1prodgwext.paylocity.com/public/security/v1/token'))
56
		},
57
		body: JSON.stringify(body)
58
	})
59
	if (!response.ok) {
60
		const text = await response.text()
61
		throw new Error(`${response.status} ${text}`)
62
	}
63
	return await response.text()
64
}
65

66
async function getOAuthToken(auth: Paylocity, tokenUrl: string): Promise<string> {
67
	const params = new URLSearchParams({
68
		grant_type: 'client_credentials',
69
		client_id: auth.clientId,
70
		client_secret: auth.clientSecret
71
	})
72

73
	const response = await fetch(tokenUrl, {
74
		method: 'POST',
75
		headers: {
76
			Authorization: 'Basic ' + btoa(`${auth.clientId}:${auth.clientSecret}`),
77
			'Content-Type': 'application/x-www-form-urlencoded'
78
		},
79
		body: params.toString()
80
	})
81

82
	if (!response.ok) {
83
		const text = await response.text()
84
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
85
	}
86

87
	const data = await response.json()
88
	return data.access_token
89
}
90