0

Worker Communication

by
Published Oct 17, 2025

Update a "Active" or "In-progress" workers specific communication item.

Script paychex Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Worker Communication
4
 * Update a "Active" or "In-progress" workers specific communication item.
5
 */
6
export async function main(
7
	auth: RT.Paychex,
8
	workerId: string,
9
	communicationId: string,
10
	body: Body
11
) {
12
	const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token')
13
	const url = new URL(
14
		`https://api.paychex.com/workers/${workerId}/communications/${communicationId}`
15
	)
16

17
	const response = await fetch(url, {
18
		method: 'PATCH',
19
		headers: {
20
			'Content-Type': 'application/json',
21
			Authorization: 'Bearer ' + accessToken
22
		},
23
		body: JSON.stringify(body)
24
	})
25
	if (!response.ok) {
26
		const text = await response.text()
27
		throw new Error(`${response.status} ${text}`)
28
	}
29
	return await response.json()
30
}
31

32
async function getOAuthToken(auth: RT.Paychex, tokenUrl: string): Promise<string> {
33
	const params = new URLSearchParams({
34
		grant_type: 'client_credentials'
35
	})
36

37
	const response = await fetch(tokenUrl, {
38
		method: 'POST',
39
		headers: {
40
			Authorization: 'Basic ' + btoa(`${auth.client_id}:${auth.client_secret}`),
41
			'Content-Type': 'application/x-www-form-urlencoded'
42
		},
43
		body: params.toString()
44
	})
45

46
	if (!response.ok) {
47
		const text = await response.text()
48
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
49
	}
50

51
	const data = await response.json()
52
	return data.access_token
53
}
54

55
/* eslint-disable */
56
/**
57
 * This file was automatically generated by json-schema-to-typescript.
58
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
59
 * and run json-schema-to-typescript to regenerate this file.
60
 */
61

62
export interface Body {
63
	/**
64
	 * The ID for the workers specific communication item.
65
	 */
66
	communicationId?: string
67
	/**
68
	 * A set of communication types classifying an instruction that the customer, requester, or subject must comply with in order for the screening to go forward. NOTE: PHONE and EMAIL type supports BUSINESS and PERSONAL usage type only.MOBILE_PHONE, FAX and PAGER supports BUSINESS usage type only.This data field cannot be PATCHED.
69
	 */
70
	type?: 'STREET_ADDRESS' | 'PO_BOX_ADDRESS' | 'PHONE' | 'MOBILE_PHONE' | 'FAX' | 'EMAIL' | 'PAGER'
71
	/**
72
	 * A code classifying a designated use associated with a contact method. For example, whether a telephone or email address is one for business communications or one primarily for personal use.This data field cannot be PATCHED.
73
	 */
74
	usageType?:
75
		| 'PERSONAL'
76
		| 'BUSINESS'
77
		| 'HOME'
78
		| 'WORK'
79
		| 'LOCATION_STREET_ADDRESS'
80
		| 'MAILING_ADDRESS'
81
	/**
82
	 * The country dialing code for a communication number
83
	 */
84
	dialCountry?: string
85
	/**
86
	 * The area dialing code for a communication number
87
	 */
88
	dialArea?: string
89
	/**
90
	 * The communication number, not including country dialing or area dialing codes
91
	 */
92
	dialNumber?: string
93
	/**
94
	 * The extension of the associated communication number
95
	 */
96
	dialExtension?: string
97
	/**
98
	 * The mailto address as specified in RFC2368
99
	 */
100
	uri?: string
101
	/**
102
	 * The street address line one
103
	 */
104
	streetLineOne?: string
105
	/**
106
	 * The street address line two
107
	 */
108
	streetLineTwo?: string
109
	/**
110
	 * The postal office box. This data field cannot be PATCHED
111
	 */
112
	postOfficeBox?: string
113
	/**
114
	 * The city name
115
	 */
116
	city?: string
117
	/**
118
	 * The zip-code
119
	 */
120
	postalCode?: string
121
	/**
122
	 * The zip-code extension
123
	 */
124
	postalCodeExtension?: string
125
	/**
126
	 * The state code (ISO 3166 subdivision code)
127
	 */
128
	countrySubdivisionCode?: string
129
	/**
130
	 * The country code (ISO 3166 alpha-2)
131
	 */
132
	countryCode?: string
133
	links?: {
134
		rel?: string
135
		href?: string
136
		hreflang?: string
137
		media?: string
138
		title?: string
139
		type?: string
140
		deprecation?: string
141
		profile?: string
142
		name?: string
143
		[k: string]: unknown
144
	}[]
145
	[k: string]: unknown
146
}
147