0

Create a Government ID Number List

by
Published Apr 8, 2025

Create a new > for your organization.

Script persona Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Persona = {
3
  apiKey: string;
4
};
5
/**
6
 * Create a Government ID Number List
7
 * Create a new > for your organization.
8
 */
9
export async function main(
10
  auth: Persona,
11
  body: { data?: { attributes?: { name?: string } } },
12
  include?: string,
13
  fields?: string,
14
  Key_Inflection?: string,
15
  Idempotency_Key?: string,
16
  Persona_Version?: string,
17
) {
18
  const url = new URL(
19
    `https://api.withpersona.com/api/v1/list/government-id-numbers`,
20
  );
21
  for (const [k, v] of [
22
    ["include", include],
23
    ["fields", fields],
24
  ]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const headers: Record<string, string> = {
30
    Authorization: `Bearer ${auth.apiKey}`,
31
    "Content-Type": "application/json",
32
  };
33
  if (Key_Inflection) {
34
    headers["Key-Inflection"] = Key_Inflection;
35
  }
36
  if (Idempotency_Key) {
37
    headers["Idempotency-Key"] = Idempotency_Key;
38
  }
39
  if (Persona_Version) {
40
    headers["Persona-Version"] = Persona_Version;
41
  }
42
  const response = await fetch(url, {
43
    method: "POST",
44
    headers,
45
    body: JSON.stringify(body),
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53