0

Worker Federal Tax

by
Published Oct 17, 2025

Update the federal tax setup for an "Active" or "In-progress" worker. The patching will allow you to change the combination that you have with the extra and overrides.

Script paychex Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Worker Federal Tax
4
 * Update the federal tax setup for an "Active" or "In-progress" worker. The patching will allow you to change the combination that you have with the extra and overrides.
5
 */
6
export async function main(auth: RT.Paychex, workerId: string, body: Body) {
7
	const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token')
8
	const url = new URL(`https://api.paychex.com/workers/${workerId}/federaltax`)
9

10
	const response = await fetch(url, {
11
		method: 'PATCH',
12
		headers: {
13
			'Content-Type': 'application/json',
14
			Authorization: 'Bearer ' + accessToken
15
		},
16
		body: JSON.stringify(body)
17
	})
18
	if (!response.ok) {
19
		const text = await response.text()
20
		throw new Error(`${response.status} ${text}`)
21
	}
22
	return await response.json()
23
}
24

25
async function getOAuthToken(auth: RT.Paychex, tokenUrl: string): Promise<string> {
26
	const params = new URLSearchParams({
27
		grant_type: 'client_credentials'
28
	})
29

30
	const response = await fetch(tokenUrl, {
31
		method: 'POST',
32
		headers: {
33
			Authorization: 'Basic ' + btoa(`${auth.client_id}:${auth.client_secret}`),
34
			'Content-Type': 'application/x-www-form-urlencoded'
35
		},
36
		body: params.toString()
37
	})
38

39
	if (!response.ok) {
40
		const text = await response.text()
41
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
42
	}
43

44
	const data = await response.json()
45
	return data.access_token
46
}
47

48
/* eslint-disable */
49
/**
50
 * This file was automatically generated by json-schema-to-typescript.
51
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
52
 * and run json-schema-to-typescript to regenerate this file.
53
 */
54

55
/**
56
 * The representational state of the a worker's federal tax setup.
57
 */
58
export interface Body {
59
	/**
60
	 * The ID for the federal tax item.
61
	 */
62
	taxId?: string
63
	/**
64
	 * Filing status.
65
	 */
66
	filingStatus?:
67
		| 'SINGLE_OR_MARRIED_FILING_SEPARATELY'
68
		| 'MARRIED_FILING_JOINTLY'
69
		| 'HEAD_OF_HOUSEHOLD'
70
	/**
71
	 * See federal W-4 instructions.
72
	 */
73
	multipleJobs?: 'true' | 'false'
74
	/**
75
	 * See federal W-4 instructions.
76
	 */
77
	dependentsAmount?: string
78
	/**
79
	 * See federal W-4 instructions.
80
	 */
81
	otherIncome?: string
82
	/**
83
	 * See federal W-4 instructions.
84
	 */
85
	deductionsAmount?: string
86
	/**
87
	 * Should federal taxes be withheld:
88
	 * true means federal taxes are withheld,
89
	 * false means federal taxes are NOT withheld. Earnings will still be reported to state and federal agencies.
90
	 */
91
	taxesWithheld?: 'true' | 'false'
92
	/**
93
	 * See federal W-4 instructions. Can be used with extraWithholdingPercentage or overrideWithholdingPercentage. Cannot be used with overrideWithholdingAmount. If extraWithholdingAmount is entered, existing overrideWithholdingAmount data will be removed.
94
	 */
95
	extraWithholdingAmount?: string
96
	/**
97
	 * See federal W-4 instructions. Cannot be used with extraWithholdingAmount, extraWithholdingPercentage, or overrideWithholdingPercentage. If entered, existing extraWithholdingAmount, extraWithholdingPercentage, and overrideWithholdingPercentage data will be removed.
98
	 */
99
	overrideWithholdingAmount?: string
100
	/**
101
	 * See federal W-4 instructions. Can be used with extraWithholdingAmount. Cannot be used with overrideWithholdingAmount or overrideWithholdingPercentage. If entered, existing overrideWithholdingAmount and overrideWithholdingPercentage data will be removed.
102
	 */
103
	extraWithholdingPercentage?: string
104
	/**
105
	 * See federal W-4 instructions. Can be used with extraWithholdingAmount. Cannot be used with overrideWithholdingAmount or extraWithholdingPercentage. If entered, existing overrideWithholdingAmount and extraWithholdingPercentage data will be removed.
106
	 */
107
	overrideWithholdingPercentage?: string
108
	[k: string]: unknown
109
}
110