0

Tokens Get V2

by
Published Oct 17, 2025

Tokens Get V2

Script basis_theory Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Basistheory = {
3
  apiKey: string;
4
};
5
/**
6
 * Tokens Get V2
7
 * Tokens Get V2
8
 */
9
export async function main(
10
  auth: Basistheory,
11
  _type: string | undefined,
12
  container: string | undefined,
13
  fingerprint: string | undefined,
14
  metadata_non902_: string | undefined,
15
  start: string | undefined,
16
  size: string | undefined,
17
) {
18
  const url = new URL(`https://api.basistheory.com/v2/tokens`);
19
  for (const [k, v] of [
20
    ["type", _type],
21
    ["container", container],
22
    ["fingerprint", fingerprint],
23
    ["metadata[non902]", metadata_non902_],
24
    ["start", start],
25
    ["size", size],
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
      "BT-API-KEY": auth.apiKey,
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