0

Delete Job Code

by
Published Oct 17, 2025

**Summary Description** The DELETE Job Code endpoint enables users to delete a single job code and it’s values from the Paylocity instance of a client.

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
 * Delete Job Code
8
 * **Summary Description**
9

10
The DELETE Job Code endpoint enables users to delete a single job code and it’s values from the Paylocity instance of a client.
11
 */
12
export async function main(auth: Paylocity, companyId: string, jobCode: string) {
13
	const url = new URL(
14
		`https://dc1prodgwext.paylocity.com/apiHub/payroll/v1/companies/${companyId}/jobs/${jobCode}`
15
	)
16

17
	const response = await fetch(url, {
18
		method: 'DELETE',
19
		headers: {
20
			Authorization:
21
				'Bearer ' +
22
				(await getOAuthToken(auth, 'https://dc1prodgwext.paylocity.com/public/security/v1/token'))
23
		},
24
		body: undefined
25
	})
26
	if (!response.ok) {
27
		const text = await response.text()
28
		throw new Error(`${response.status} ${text}`)
29
	}
30
	return await response.text()
31
}
32

33
async function getOAuthToken(auth: Paylocity, tokenUrl: string): Promise<string> {
34
	const params = new URLSearchParams({
35
		grant_type: 'client_credentials',
36
		client_id: auth.clientId,
37
		client_secret: auth.clientSecret
38
	})
39

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

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

54
	const data = await response.json()
55
	return data.access_token
56
}
57