Add a Time Off Request
One script reply has been approved by the moderators Verified

A time off request is an entity that describes the decision making process for approving time off. Once a request has been created, a history entry can be created documenting the actual use of time off.

Created by hugo697 51 days ago
Submitted by hugo697 Bun
Verified 51 days ago
1
//native
2
/**
3
 * Add a Time Off Request
4
 * A time off request is an entity that describes the decision making process for approving time off. Once a request has been created, a history entry can be created documenting the actual use of time off.
5
 */
6
export async function main(auth: RT.BambooHr, employeeId: string, body: AddTimeOffRequest) {
7
	const url = new URL(
8
		`https://${auth.companyDomain}.bamboohr.com/api/v1/employees/${employeeId}/time_off/request`
9
	)
10

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

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

33
export interface AddTimeOffRequest {
34
	status?: string
35
	start?: string
36
	end?: string
37
	timeOffTypeId?: number
38
	amount?: number
39
	notes?: {
40
		from?: string
41
		note?: string
42
		[k: string]: unknown
43
	}[]
44
	dates?: {
45
		ymd?: string
46
		amount?: number
47
		[k: string]: unknown
48
	}[]
49
	[k: string]: unknown
50
}
51