0

Company Job

by
Published Oct 17, 2025

Update a single Job.

Script paychex Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Company Job
4
 * Update a single Job.
5
 */
6
export async function main(auth: RT.Paychex, companyId: string, jobId: 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/companies/${companyId}/jobs/${jobId}`)
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 state representation of Jobs within a company.
57
 */
58
export interface Body {
59
	/**
60
	 * The unique identifier associated with this job.
61
	 */
62
	jobId?: string
63
	/**
64
	 * Id that you define which is used for error handling/responses.
65
	 */
66
	jobCorrelationId?: string
67
	/**
68
	 * The name of the job.
69
	 */
70
	jobName?: string
71
	/**
72
	 * The start date associated with this job.
73
	 */
74
	startDate?: string
75
	/**
76
	 * The end date associated with this job.
77
	 */
78
	endDate?: string
79
	/**
80
	 * Date which this pay component has started for the worker.
81
	 */
82
	effectiveDate?: string
83
	links?: {
84
		rel?: string
85
		href?: string
86
		hreflang?: string
87
		media?: string
88
		title?: string
89
		type?: string
90
		deprecation?: string
91
		profile?: string
92
		name?: string
93
		[k: string]: unknown
94
	}[]
95
	/**
96
	 * Data elements of a Job Number to show the segments and number.For segmentation this can be up to 3 different segments.
97
	 */
98
	jobNumber?: {
99
		/**
100
		 * This is segment 1 or the number associated to the job when segmentation is not used.
101
		 */
102
		segment1?: string
103
		/**
104
		 * This is segment 2.
105
		 */
106
		segment2?: string
107
		/**
108
		 * This is segment 3.
109
		 */
110
		segment3?: string
111
		[k: string]: unknown
112
	}
113
	[k: string]: unknown
114
}
115