0

Create Moti

by
Published Nov 5, 2024

Creates a Moti.

Script motimate Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Motimate = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Motimate,
8
	body: {
9
		badge_id: number
10
		external_id?: string
11
		default_language:
12
			| 'cs'
13
			| 'da'
14
			| 'de'
15
			| 'en'
16
			| 'es'
17
			| 'fi'
18
			| 'fr'
19
			| 'hr'
20
			| 'hu'
21
			| 'it'
22
			| 'lt'
23
			| 'lv'
24
			| 'nb'
25
			| 'nl'
26
			| 'nn'
27
			| 'pl'
28
			| 'pt'
29
			| 'ro'
30
			| 'ru'
31
			| 'se'
32
			| 'sq'
33
			| 'sr'
34
			| 'sv'
35
			| 'tr'
36
		color: string
37
		title: string
38
		description?: string
39
		locked_order?: false | true
40
		folder_id?: number
41
		approver_id?: number
42
		approver_external_id?: number
43
		tags?: string[]
44
		category_ids?: string[]
45
		category_external_ids?: string[]
46
	}
47
) {
48
	const url = new URL(`https://motimateapp.com/public_api/motis`)
49

50
	const response = await fetch(url, {
51
		method: 'POST',
52
		headers: {
53
			'Content-Type': 'application/json',
54
			Authorization: 'Bearer ' + auth.token
55
		},
56
		body: JSON.stringify(body)
57
	})
58

59
	if (!response.ok) {
60
		const text = await response.text()
61
		throw new Error(`${response.status} ${text}`)
62
	}
63

64
	return await response.json()
65
}
66