0

Create Assignment

by
Published Nov 5, 2024

Creates an Assignment.

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
		learning_type: 'learning_path' | 'moti' | 'package'
10
		learning_id: number
11
		group_ids: number
12
		position_ids: number
13
		group_external_ids: string
14
		position_external_ids: string
15
	}
16
) {
17
	const url = new URL(`https://motimateapp.com/public_api/assignments`)
18

19
	const response = await fetch(url, {
20
		method: 'POST',
21
		headers: {
22
			'Content-Type': 'application/json',
23
			Authorization: 'Bearer ' + auth.token
24
		},
25
		body: JSON.stringify(body)
26
	})
27

28
	if (!response.ok) {
29
		const text = await response.text()
30
		throw new Error(`${response.status} ${text}`)
31
	}
32

33
	return await response.text()
34
}
35