0

List Attendances

by
Published Oct 17, 2025

Fetch attendance data for the company employees. The result can be `paginated` and `filtered` by period, the date and/or time they were updated, and/or specific employee/employees. The result contains a list of attendances.

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
 * List Attendances
8
 * Fetch attendance data for the company employees. The result can be `paginated` and `filtered` by period, the date and/or time they were updated, and/or specific employee/employees. The result contains a list of attendances.
9
 */
10
export async function main(
11
	auth: Personio,
12
	start_date: string | undefined,
13
	end_date: string | undefined,
14
	updated_from: string | undefined,
15
	updated_to: string | undefined,
16
	includePending: string | undefined,
17
	employees__: string | undefined,
18
	limit: string | undefined,
19
	offset: string | undefined,
20
	X_Personio_Partner_ID?: string,
21
	X_Personio_App_ID?: string
22
) {
23
	const url = new URL(`https://api.personio.de/v1/company/attendances`)
24
	for (const [k, v] of [
25
		['start_date', start_date],
26
		['end_date', end_date],
27
		['updated_from', updated_from],
28
		['updated_to', updated_to],
29
		['includePending', includePending],
30
		['employees[]', employees__],
31
		['limit', limit],
32
		['offset', offset]
33
	]) {
34
		if (v !== undefined && v !== '' && k !== undefined) {
35
			url.searchParams.append(k, v)
36
		}
37
	}
38
	const response = await fetch(url, {
39
		method: 'GET',
40
		headers: {
41
			...(X_Personio_Partner_ID ? { 'X-Personio-Partner-ID': X_Personio_Partner_ID } : {}),
42
			...(X_Personio_App_ID ? { 'X-Personio-App-ID': X_Personio_App_ID } : {}),
43
			Authorization: 'Bearer ' + (await getOAuthToken(auth, 'https://api.personio.de/oauth2/token'))
44
		},
45
		body: undefined
46
	})
47
	if (!response.ok) {
48
		const text = await response.text()
49
		throw new Error(`${response.status} ${text}`)
50
	}
51
	return await response.json()
52
}
53

54
async function getOAuthToken(auth: Personio, tokenUrl: string): Promise<string> {
55
	const params = new URLSearchParams({
56
		grant_type: 'client_credentials',
57
		client_id: auth.clientId,
58
		client_secret: auth.clientSecret
59
	})
60

61
	const response = await fetch(tokenUrl, {
62
		method: 'POST',
63
		headers: {
64
			Authorization: 'Basic ' + btoa(`${auth.clientId}:${auth.clientSecret}`),
65
			'Content-Type': 'application/x-www-form-urlencoded'
66
		},
67
		body: params.toString()
68
	})
69

70
	if (!response.ok) {
71
		const text = await response.text()
72
		throw new Error(`OAuth token request failed: ${response.status} ${text}`)
73
	}
74

75
	const data = await response.json()
76
	return data.access_token
77
}
78