0

List account jobs

by
Published Oct 17, 2025

List all jobs for the given account.

Script phrase Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Phrase = {
3
	token: string
4
	baseUrl: string
5
}
6
/**
7
 * List account jobs
8
 * List all jobs for the given account.
9
 */
10
export async function main(
11
	auth: Phrase,
12
	account_id: string,
13
	page: string | undefined,
14
	per_page: string | undefined,
15
	owned_by: string | undefined,
16
	assigned_to: string | undefined,
17
	state: string | undefined
18
) {
19
	const url = new URL(`${auth.baseUrl}/accounts/${account_id}/jobs`)
20
	for (const [k, v] of [
21
		['page', page],
22
		['per_page', per_page],
23
		['owned_by', owned_by],
24
		['assigned_to', assigned_to],
25
		['state', state]
26
	]) {
27
		if (v !== undefined && v !== '' && k !== undefined) {
28
			url.searchParams.append(k, v)
29
		}
30
	}
31
	const response = await fetch(url, {
32
		method: 'GET',
33
		headers: {
34
			Authorization: 'ApiToken ' + auth.token
35
		},
36
		body: undefined
37
	})
38
	if (!response.ok) {
39
		const text = await response.text()
40
		throw new Error(`${response.status} ${text}`)
41
	}
42
	return await response.json()
43
}
44