0

Custom Fields Category

by
Published Oct 17, 2025

Update CustomFieldsCategory at the company level.

Script paychex Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Custom Fields Category
4
 * Update  CustomFieldsCategory at the company level.
5
 */
6
export async function main(auth: RT.Paychex, companyId: string, categoryid: string, body: Body) {
7
	const accessToken = await getOAuthToken(auth, 'https://api.paychex.com/auth/oauth/v2/token')
8
	const url = new URL(
9
		`https://api.paychex.com/companies/${companyId}/customfieldscategories/${categoryid}`
10
	)
11

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

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

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

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

46
	const data = await response.json()
47
	return data.access_token
48
}
49

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

57
export interface Body {
58
	/**
59
	 * The unique identifier that is autogenerated when creating a category
60
	 */
61
	categoryId?: string
62
	/**
63
	 * The name of the Category
64
	 */
65
	categoryName?: string
66
	links?: {
67
		rel?: string
68
		href?: string
69
		hreflang?: string
70
		media?: string
71
		title?: string
72
		type?: string
73
		deprecation?: string
74
		profile?: string
75
		name?: string
76
		[k: string]: unknown
77
	}[]
78
	[k: string]: unknown
79
}
80