0

List corpora

by
Published Nov 5, 2024

List corpora in the account. The corpus objects that are returned are less detailed than the direct corpus retrieval operation.

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 corpora
7
 * List corpora in the account. The corpus objects that are returned are less
8
detailed than the direct corpus retrieval operation.
9

10
 */
11
export async function main(
12
	auth: Vectara,
13
	limit: string | undefined,
14
	filter: string | undefined,
15
	page_key: string | undefined
16
) {
17
	const url = new URL(`https://api.vectara.io/v2/corpora`)
18
	for (const [k, v] of [
19
		['limit', limit],
20
		['filter', filter],
21
		['page_key', page_key]
22
	]) {
23
		if (v !== undefined && v !== '' && k !== undefined) {
24
			url.searchParams.append(k, v)
25
		}
26
	}
27
	const response = await fetch(url, {
28
		method: 'GET',
29
		headers: {
30
			'x-api-key': auth.apiKey
31
		},
32
		body: undefined
33
	})
34
	if (!response.ok) {
35
		const text = await response.text()
36
		throw new Error(`${response.status} ${text}`)
37
	}
38
	return await response.json()
39
}
40