Add Webhook
One script reply has been approved by the moderators Verified

Add a new Webhook. For more details or instructions you can refer to the webhooks documentation.

Created by hugo697 51 days ago
Submitted by hugo697 Bun
Verified 51 days ago
1
//native
2
/**
3
 * Add Webhook
4
 * Add a new Webhook. For more details or instructions you can refer to the [webhooks documentation](https://documentation.bamboohr.com/docs/webhooks-2).
5
 */
6
export async function main(auth: RT.BambooHr, body: AddWebhook) {
7
	const url = new URL(`https://${auth.companyDomain}.bamboohr.com/api/v1/webhooks`)
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 AddWebhook {
32
	/**
33
	 * The name of the webhook.
34
	 */
35
	name: string
36
	/**
37
	 * A list of fields to monitor.
38
	 */
39
	monitorFields: string[]
40
	/**
41
	 * A list of fields to post to the webhook url. Field ID or alias: external name
42
	 */
43
	postFields: {
44
		[k: string]: unknown
45
	}
46
	/**
47
	 * The url the webhook should send data to (must begin with https://).
48
	 */
49
	url: string
50
	/**
51
	 * The format the webhook should use (json - default, form-encoded).
52
	 */
53
	format?: 'json' | 'form-encoded'
54
	/**
55
	 * How often the webhook could fire.
56
	 */
57
	frequency?: {
58
		/**
59
		 * The hour to potentially fire (0-23, null to potentially fire every hour)
60
		 */
61
		hour?: number
62
		/**
63
		 * The minute to potentially fire (0-59, null to potentially fire every minute)
64
		 */
65
		minute?: number
66
		/**
67
		 * The day to potentially fire (1-31, null to potentially fire every day)
68
		 */
69
		day?: number
70
		/**
71
		 * The month to potentially fire (1-12, null to potentially fire every month)
72
		 */
73
		month?: number
74
		[k: string]: unknown
75
	}
76
	/**
77
	 * To limit how often to potentially fire a webhook, and maximum amount of records to send
78
	 */
79
	limit?: {
80
		/**
81
		 * The amount of records to send
82
		 */
83
		times?: number
84
		/**
85
		 * The minimum amount of seconds between requests
86
		 */
87
		seconds?: number
88
		[k: string]: unknown
89
	}
90
	/**
91
	 * If set to true, the company domain will be added to the header.
92
	 */
93
	includeCompanyDomain?: boolean
94
	[k: string]: unknown
95
}
96