0

List jobs

by
Published Nov 5, 2024

List jobs for the account. Jobs are background processes like replacing the filterable metadata attributes.

Script vectara Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Vectara = {
3
	apiKey: string
4
}
5
/**
6
 * List jobs
7
 * List jobs for the account. Jobs are background processes like replacing the filterable metadata attributes.
8
 */
9
export async function main(
10
	auth: Vectara,
11
	corpus_key: string | undefined,
12
	after: string | undefined,
13
	state: string | undefined,
14
	limit: string | undefined,
15
	page_key: string | undefined
16
) {
17
	const url = new URL(`https://api.vectara.io/v2/jobs`)
18
	for (const [k, v] of [
19
		['corpus_key', corpus_key],
20
		['after', after],
21
		['state', state],
22
		['limit', limit],
23
		['page_key', page_key]
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
			'x-api-key': auth.apiKey
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.json()
41
}
42