1 | |
2 | type Persona = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Import Government ID Number Lists |
7 | * Bulk import government ID number List Items by uploading a CSV file. |
8 |
|
9 | Each row should be the details for a new List Item. The columns we allow are: |
10 | - id_number |
11 | - id_class |
12 |
|
13 | Common values for id_class include `pp` for passport and `dl` for driver license. Please contact us or reach out to [support@withpersona.com](mailto:support@withpersona.com) if you need help getting id_class values. |
14 | */ |
15 | export async function main( |
16 | auth: Persona, |
17 | body: { |
18 | data: { |
19 | attributes: { |
20 | file: { data?: string; filename?: string }; |
21 | "list-id": string; |
22 | }; |
23 | }; |
24 | }, |
25 | include?: string, |
26 | fields?: string, |
27 | Key_Inflection?: string, |
28 | Idempotency_Key?: string, |
29 | Persona_Version?: string, |
30 | ) { |
31 | const url = new URL( |
32 | `https://api.withpersona.com/api/v1/importer/list-item/government-id-numbers`, |
33 | ); |
34 | for (const [k, v] of [ |
35 | ["include", include], |
36 | ["fields", fields], |
37 | ]) { |
38 | if (v !== undefined && v !== "" && k !== undefined) { |
39 | url.searchParams.append(k, v); |
40 | } |
41 | } |
42 | const formData = new FormData(); |
43 | for (const [k, v] of Object.entries(body)) { |
44 | if (v !== undefined) { |
45 | formData.append(k, String(v)); |
46 | } |
47 | } |
48 | const headers: Record<string, string> = { |
49 | Authorization: `Bearer ${auth.apiKey}`, |
50 | "Content-Type": "application/json", |
51 | }; |
52 | if (Key_Inflection) { |
53 | headers["Key-Inflection"] = Key_Inflection; |
54 | } |
55 | if (Idempotency_Key) { |
56 | headers["Idempotency-Key"] = Idempotency_Key; |
57 | } |
58 | if (Persona_Version) { |
59 | headers["Persona-Version"] = Persona_Version; |
60 | } |
61 | const response = await fetch(url, { |
62 | method: "POST", |
63 | headers, |
64 | body: JSON.stringify(body), |
65 | }); |
66 | if (!response.ok) { |
67 | const text = await response.text(); |
68 | throw new Error(`${response.status} ${text}`); |
69 | } |
70 | return await response.json(); |
71 | } |
72 |
|