0

Create time-off request

by
Published Oct 17, 2025

Create time-off request **Token scopes**: `time-off:write`

Script deel Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Create time-off request
4
 * Create time-off request
5
 **Token scopes**: `time-off:write`
6
 */
7
export async function main(auth: RT.Deel, body: Body) {
8
	const url = new URL(`https://api.letsdeel.com/rest/v2/time_offs`)
9

10
	const formData = new FormData()
11
	for (const [k, v] of Object.entries(body)) {
12
		if (v !== undefined && v !== '') {
13
			formData.append(k, String(v))
14
		}
15
	}
16
	const response = await fetch(url, {
17
		method: 'POST',
18
		headers: {
19
			'Content-Type': 'application/json',
20
			Authorization: 'Bearer ' + auth.apiKey
21
		},
22
		body: JSON.stringify(body)
23
	})
24
	if (!response.ok) {
25
		const text = await response.text()
26
		throw new Error(`${response.status} ${text}`)
27
	}
28
	return await response.json()
29
}
30

31
/* eslint-disable */
32
/**
33
 * This file was automatically generated by json-schema-to-typescript.
34
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
35
 * and run json-schema-to-typescript to regenerate this file.
36
 */
37

38
/**
39
 * The time off request data
40
 */
41
export interface Body {
42
	/**
43
	 * The time off request data
44
	 */
45
	data?: {
46
		/**
47
		 * The dates breakdown for the time off request.
48
		 */
49
		dates?: {
50
			date: string | string
51
			/**
52
			 * The amount taken in hours during this specific date. It can not exceed the maximum allowed hours for the date.
53
			 */
54
			hours?: number
55
			/**
56
			 * The amount of time off requested for the date. It must be in the same time unit as in the total amount for the time off request.
57
			 */
58
			amount?: number
59
			/**
60
			 * The type of day for the time off request. All dates must follow the same type.
61
			 */
62
			day_type?: 'HALF_DAY' | 'FULL_DAY' | 'PERCENTAGE' | 'HOURLY'
63
			[k: string]: unknown
64
		}[]
65
		/**
66
		 * Reason for taking time off. This is complementary information for the time-off description. Useful to provide sub categories for the same policy.
67
		 */
68
		reason?: string
69
		/**
70
		 * Status for the time off request. When set to REQUESTED the time off should be reviewed later through the Approve/Reject time off api.
71
		 */
72
		status?: 'REQUESTED' | 'APPROVED'
73
		/**
74
		 * Whether the time off is paid or unpaid. By default it follows the policy configuration.
75
		 */
76
		is_paid?: boolean
77
		end_date: string
78
		/**
79
		 * The time off policy id. Can be used in place of time_off_type_id
80
		 */
81
		policy_id?: string
82
		start_date: string
83
		/**
84
		 * Description of the time off request. Some policies require that a description is provided.
85
		 */
86
		description?: string
87
		/**
88
		 * Contract id. This is the id of the contract associated with the time off request.
89
		 */
90
		contract_oid?: string
91
		/**
92
		 * Details of the event associated with the time off request. Required for event based policies such as parental leave.
93
		 */
94
		event_details?: {
95
			/**
96
			 * The birth date of the child. This is used for parental leave requests.
97
			 */
98
			birth_date: string
99
			/**
100
			 * The date of adoption. This is used for parental leave requests.
101
			 */
102
			adoption_date?: string
103
			/**
104
			 * Whether the birth was premature or not. This is used for parental leave requests.
105
			 */
106
			was_premature_birth: boolean
107
			/**
108
			 * Whether the birth was multiple or not. This is used for parental leave requests.
109
			 */
110
			had_multiple_children: boolean
111
			[k: string]: unknown
112
		}
113
		/**
114
		 * Deduction amount. Available for independent contractor's policies
115
		 */
116
		deduction_amount?: number
117
		/**
118
		 * The time off type id. Required when policy_id is not provided
119
		 */
120
		time_off_type_id?: string
121
		/**
122
		 * The time off event id. This is used to link the time off request to an event.
123
		 */
124
		time_off_event_id?: string
125
		/**
126
		 * This is the percentage of time off taken. This is used when the time off request is a percentage.
127
		 */
128
		time_off_percentage?: number
129
		/**
130
		 * The hris profile id of the recipient
131
		 */
132
		recipient_profile_id: string
133
		/**
134
		 * Description of the time off type. This is used when the policy is OTHER.
135
		 */
136
		other_type_description?: string
137
		[k: string]: unknown
138
	}
139
	[k: string]: unknown
140
}
141