0

Create Compensation Types

by
Published Oct 17, 2025

Creates a new Compensation Type and returns the created resource with its UUID. This UUID can be used to create a new compensation. The types include one-time and recurring Compensation Types for salary workers. Hourly types are not supported and bonuses should use recurring or one time types. [Click here for more information.](https://support.personio.de/hc/en-us/articles/15465321997853-Alpha-Test-I-The-Payroll-API)

Script personio Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Personio = {
3
	clientId: string
4
	clientSecret: string
5
}
6
/**
7
 * Create Compensation Types
8
 * Creates a new Compensation Type and returns the created resource with its UUID. This UUID can be used to create a new compensation. The types include one-time and recurring Compensation Types for salary workers. Hourly types are not supported and bonuses should use recurring or one time types. [Click here for more information.](https://support.personio.de/hc/en-us/articles/15465321997853-Alpha-Test-I-The-Payroll-API)
9

10
 */
11
export async function main(
12
	auth: Personio,
13
	body: { name: string; category: 'RECURRING' | 'ONE_TIME' }
14
) {
15
	const url = new URL(`https://api.personio.de/v2/compensations/types`)
16

17
	const response = await fetch(url, {
18
		method: 'POST',
19
		headers: {
20
			'Content-Type': 'application/json',
21
			Authorization: 'Bearer ' + (await getOAuthToken(auth, 'https://api.personio.de/oauth2/token'))
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: Personio, tokenUrl: string): Promise<string> {
33
	const params = new URLSearchParams({
34
		grant_type: 'client_credentials',
35
		client_id: auth.clientId,
36
		client_secret: auth.clientSecret
37
	})
38

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

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

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