0
Get jobs
One script reply has been approved by the moderators Verified

List All jobs

Created by hugo697 2 days ago Viewed 0 times
0
Submitted by hugo697 Bun
Verified 2 days ago
1
//native
2
type Botify = {
3
	token: string
4
}
5
/**
6
 * Get jobs
7
 * List All jobs
8
 */
9
export async function main(
10
	auth: Botify,
11
	page: string | undefined,
12
	size: string | undefined,
13
	job_type: string | undefined,
14
	project: string | undefined,
15
	analysis: string | undefined
16
) {
17
	const url = new URL(`https://api.botify.com/jobs`)
18
	for (const [k, v] of [
19
		['page', page],
20
		['size', size],
21
		['job_type', job_type],
22
		['project', project],
23
		['analysis', analysis]
24
	]) {
25
		if (v !== undefined && v !== '' && k !== undefined) {
26
			url.searchParams.append(k, v)
27
		}
28
	}
29
	const response = await fetch(url, {
30
		method: 'GET',
31
		headers: {
32
			Authorization: 'Token ' + auth.token
33
		},
34
		body: undefined
35
	})
36
	if (!response.ok) {
37
		const text = await response.text()
38
		throw new Error(`${response.status} ${text}`)
39
	}
40
	return await response.text()
41
}
42