0

Fetch Moti Editors

by
Published Nov 5, 2024

Fetches Editors, i.e. relationships between Motis and Users which shows which User can edit which 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
	filter_moti_id_: string | undefined,
9
	filter_moti_external_id_: string | undefined,
10
	filter_user_id_: string | undefined,
11
	filter_user_external_id_: string | undefined
12
) {
13
	const url = new URL(`https://motimateapp.com/public_api/moti_editors`)
14

15
	for (const [k, v] of [
16
		['filter[moti_id]', filter_moti_id_],
17
		['filter[moti_external_id]', filter_moti_external_id_],
18
		['filter[user_id]', filter_user_id_],
19
		['filter[user_external_id]', filter_user_external_id_]
20
	]) {
21
		if (v !== undefined && v !== '' && k !== undefined) {
22
			url.searchParams.append(k, v)
23
		}
24
	}
25

26
	const response = await fetch(url, {
27
		method: 'GET',
28
		headers: {
29
			Authorization: 'Bearer ' + auth.token
30
		}
31
	})
32

33
	if (!response.ok) {
34
		const text = await response.text()
35
		throw new Error(`${response.status} ${text}`)
36
	}
37

38
	return await response.json()
39
}
40