0

List Api Requests

by
Published Apr 8, 2025
Script buttondown Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Buttondown = {
3
  token: string;
4
};
5
/**
6
 * List Api Requests
7
 *
8
 */
9
export async function main(
10
  auth: Buttondown,
11
  status_code: string | undefined,
12
  method: string | undefined,
13
  source: string | undefined,
14
  version: string | undefined,
15
  page: string | undefined,
16
) {
17
  const url = new URL(`https://api.buttondown.com/v1/api_requests`);
18
  for (const [k, v] of [
19
    ["status_code", status_code],
20
    ["method", method],
21
    ["source", source],
22
    ["version", version],
23
    ["page", page],
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.json();
41
}
42