0

Get a list of operations

by
Published Apr 8, 2025

Retrieves a list of operations for the specified Neon project. You can obtain a `project_id` by listing the projects for your Neon account. The number of operations returned can be large. To paginate the response, issue an initial request with a `limit` value. Then, add the `cursor` value that was returned in the response to the next request.

Script neondb Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Neondb = {
3
	apiKey: string
4
}
5
/**
6
 * Get a list of operations
7
 * Retrieves a list of operations for the specified Neon project.
8
You can obtain a `project_id` by listing the projects for your Neon account.
9
The number of operations returned can be large.
10
To paginate the response, issue an initial request with a `limit` value.
11
Then, add the `cursor` value that was returned in the response to the next request.
12

13
 */
14
export async function main(
15
	auth: Neondb,
16
	project_id: string,
17
	cursor: string | undefined,
18
	limit: string | undefined
19
) {
20
	const url = new URL(`https://console.neon.tech/api/v2/projects/${project_id}/operations`)
21
	for (const [k, v] of [
22
		['cursor', cursor],
23
		['limit', limit]
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: 'Bearer ' + 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