Add Training Type
One script reply has been approved by the moderators Verified

Add a training type. The owner of the API key used must have access to training settings.

Created by hugo697 51 days ago
Submitted by hugo697 Bun
Verified 51 days ago
1
//native
2
/**
3
 * Add Training Type
4
 * Add a training type. The owner of the API key used must have access to training settings.
5
 */
6
export async function main(auth: RT.BambooHr, body: Body) {
7
	const url = new URL(`https://${auth.companyDomain}.bamboohr.com/api/v1/training/type`)
8

9
	const response = await fetch(url, {
10
		method: 'POST',
11
		headers: {
12
			'Content-Type': 'application/json',
13
			Authorization: 'Basic ' + btoa(`${auth.apiKey}:x`)
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
	/**
33
	 * Name of the new training type.
34
	 */
35
	name: string
36
	/**
37
	 * The frequency is the (optional) amount of months between renewing trainings. Not valid if training are not renewable.
38
	 */
39
	frequency?: number
40
	/**
41
	 * Renewable is optional but if you are setting it to true you must pass a frequency which is the months between renewals.
42
	 */
43
	renewable?: boolean
44
	/**
45
	 * The category is optional and you can pass either a category id or a category name.
46
	 */
47
	category?: {
48
		/**
49
		 * Category ID
50
		 */
51
		id?: number
52
		/**
53
		 * Category Name
54
		 */
55
		name?: string
56
		/**
57
		 * Accuracy in meters of the clock in location
58
		 */
59
		accuracy?: number
60
		/**
61
		 * Address...
62
		 */
63
		address?: string
64
		[k: string]: unknown
65
	}
66
	/**
67
	 * Is this a required training?
68
	 */
69
	required: boolean
70
	/**
71
	 * Number of days before the training is due for new hires. Not valid unless training is required.
72
	 */
73
	dueFromHireDate?: number
74
	/**
75
	 * Optional URL that can be included with a training.
76
	 */
77
	linkUrl?: string
78
	/**
79
	 * Description for the training.
80
	 */
81
	description?: string
82
	/**
83
	 * Allows all employees who can view the training to be able to mark it complete.
84
	 */
85
	allowEmployeesToMarkComplete?: boolean
86
	[k: string]: unknown
87
}
88