0

External HR Time Off Synchronization

by
Published Oct 17, 2025

Synchronize time off requests from an external HRIS to Deel.

Script deel Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * External HR Time Off Synchronization
4
 * Synchronize time off requests from an external HRIS to Deel.
5
 */
6
export async function main(auth: RT.Deel, body: Body) {
7
	const url = new URL(`https://api.letsdeel.com/rest/v2/time_offs/global-payroll/sync`)
8

9
	const response = await fetch(url, {
10
		method: 'POST',
11
		headers: {
12
			'Content-Type': 'application/json',
13
			Authorization: 'Bearer ' + auth.apiKey
14
		},
15
		body: JSON.stringify(body)
16
	})
17
	if (!response.ok) {
18
		const text = await response.text()
19
		throw new Error(`${response.status} ${text}`)
20
	}
21
	return await response.json()
22
}
23

24
/* eslint-disable */
25
/**
26
 * This file was automatically generated by json-schema-to-typescript.
27
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
28
 * and run json-schema-to-typescript to regenerate this file.
29
 */
30

31
export interface Body {
32
	data?: {
33
		time_offs: (
34
			| {
35
					/**
36
					 * The amount in time units for this time off. When no amount is informed, it will be calculated using work schedules and public holidays defined at Deel.
37
					 */
38
					amount?: number
39
					/**
40
					 * Allows the consumer to specify whether the time off is considered as paid (at statutory) or unpaid based on the configuration of the policy in the external HRIS.
41
					 */
42
					is_paid?: boolean
43
					/**
44
					 * The end date of the time off.
45
					 */
46
					end_date: string
47
					/**
48
					 * The start date of the time off.
49
					 */
50
					start_date: string
51
					/**
52
					 * The approval date of the time off. If no approval date is informed, the start date of this request will be used as the approval date. Note: use this field in order to support retrospective leaves so Deel can identify requests made after the payroll cycle.
53
					 */
54
					approved_at?: string
55
					/**
56
					 * The description of the time off.
57
					 */
58
					description?: string
59
					/**
60
					 * External ID to link a Deel time off object with an external time off object. It will be used to determine which operation should be done: INSERT, UPDATE or DELETE.
61
					 */
62
					external_id: string
63
					/**
64
					 * The policy name the time off is being requested for. If not informed, a default name will be generated using the policy type and contract's country (eg: Vacation - US).
65
					 */
66
					policy_name?: string
67
					/**
68
					 * The Deel policy type of the policy the time off is being requested for.
69
					 */
70
					policy_type:
71
						| 'Adoption leave'
72
						| 'Advanced vacation'
73
						| 'Bereavement leave'
74
						| 'Blood donation leave'
75
						| 'Breastfeeding leave'
76
						| 'Childbirth leave'
77
						| 'Childcare leave'
78
						| 'Civic/public duty leave'
79
						| 'Disability leave'
80
						| "Doctor's appointment leave"
81
						| 'Family & domestic violence leave'
82
						| 'Floating Holiday Allowance'
83
						| 'Hajj leave'
84
						| 'Marriage/wedding leave'
85
						| 'Maternity leave'
86
						| 'Military leave'
87
						| 'Moving leave'
88
						| 'Other leave'
89
						| 'Paid leave'
90
						| 'Parental leave'
91
						| 'Paternity leave'
92
						| 'Personal leave'
93
						| 'Pregnancy leave'
94
						| 'Regional holiday'
95
						| 'RTT'
96
						| 'Sick leave'
97
						| 'Study leave'
98
						| 'Supplementary Leave'
99
						| 'Unpaid leave'
100
						| 'Vacation'
101
						| 'Volunteer leave'
102
						| 'Work accident leave'
103
					/**
104
					 * The contract id that has requested the time off.
105
					 */
106
					contract_oid: string
107
					/**
108
					 * The request date of the time off.
109
					 */
110
					requested_at?: string
111
					/**
112
					 * The time unit for this time off. *Mandatory when amount parameter is informed*. If no amount and no entitlement_unit are informed, it will be calculated using Deel's internal country templates for compliant time off policies.
113
					 */
114
					entitlement_unit?: 'HOUR' | 'BUSINESS_DAY' | 'CALENDAR_DAY' | 'WEEK' | 'MONTH' | 'YEAR'
115
					[k: string]: unknown
116
			  }
117
			| {
118
					/**
119
					 * Indicates this time off request must be deleted
120
					 */
121
					deleted: true
122
					/**
123
					 * External ID to link a Deel time off object with an external time off object. It will be used to determine which operation should be done: INSERT, UPDATE or DELETE.
124
					 */
125
					external_id: string
126
					/**
127
					 * The contract id that has requested the time off.
128
					 */
129
					contract_oid: string
130
					[k: string]: unknown
131
			  }
132
		)[]
133
		[k: string]: unknown
134
	}
135
	[k: string]: unknown
136
}
137