0

List policies

by
Published Oct 17, 2025

List policies **Token scopes**: `time-off:read`

Script deel Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * List policies
4
 * List policies
5
 **Token scopes**: `time-off:read`
6
 */
7
export async function main(
8
	auth: RT.Deel,
9
	hris_profile_id: string,
10
	policy_type_name?:
11
		| 'Moving leave'
12
		| 'Adoption leave'
13
		| 'Personal leave'
14
		| 'Parental leave'
15
		| 'Military leave'
16
		| 'Childbirth leave'
17
		| 'Study leave'
18
		| 'Sick leave'
19
		| 'Bereavement leave'
20
		| 'Family & domestic violence leave'
21
		| 'Marriage/wedding leave'
22
		| 'Blood donation leave'
23
		| 'Volunteer leave'
24
		| 'Vacation'
25
		| "Doctor's appointment leave"
26
		| 'Maternity leave'
27
		| 'Hajj leave'
28
		| 'Paternity leave'
29
		| 'Civic/public duty leave'
30
		| 'Childcare leave'
31
		| 'Unpaid leave'
32
		| 'Paid leave'
33
		| 'Other leave'
34
		| 'Disability leave'
35
		| 'Pregnancy leave'
36
		| 'RTT'
37
		| 'Regional holiday'
38
		| 'Breastfeeding leave'
39
		| 'Advanced vacation'
40
		| undefined,
41
	policy_type_id?: string | undefined
42
) {
43
	const url = new URL(
44
		`https://api.letsdeel.com/rest/v2/time_offs/profile/${hris_profile_id}/policies`
45
	)
46
	for (const [k, v] of [
47
		['policy_type_name', policy_type_name],
48
		['policy_type_id', policy_type_id]
49
	]) {
50
		if (v !== undefined && v !== '') {
51
			url.searchParams.append(k, v)
52
		}
53
	}
54
	const response = await fetch(url, {
55
		method: 'GET',
56
		headers: {
57
			Authorization: 'Bearer ' + auth.apiKey
58
		},
59
		body: undefined
60
	})
61
	if (!response.ok) {
62
		const text = await response.text()
63
		throw new Error(`${response.status} ${text}`)
64
	}
65
	return await response.json()
66
}
67