1 | |
2 | type Persona = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Decline an Inquiry |
7 | * Declines an >. |
8 | Note that this action will trigger any associated workflows and webhooks. |
9 | */ |
10 | export async function main( |
11 | auth: Persona, |
12 | inquiry_id: string, |
13 | body: { meta?: { comment?: string } }, |
14 | include?: string, |
15 | fields?: string, |
16 | Key_Inflection?: string, |
17 | Idempotency_Key?: string, |
18 | Persona_Version?: string, |
19 | ) { |
20 | const url = new URL( |
21 | `https://api.withpersona.com/api/v1/inquiries/${inquiry_id}/decline`, |
22 | ); |
23 | for (const [k, v] of [ |
24 | ["include", include], |
25 | ["fields", fields], |
26 | ]) { |
27 | if (v !== undefined && v !== "" && k !== undefined) { |
28 | url.searchParams.append(k, v); |
29 | } |
30 | } |
31 | const headers: Record<string, string> = { |
32 | Authorization: `Bearer ${auth.apiKey}`, |
33 | "Content-Type": "application/json", |
34 | }; |
35 | if (Key_Inflection) { |
36 | headers["Key-Inflection"] = Key_Inflection; |
37 | } |
38 | if (Idempotency_Key) { |
39 | headers["Idempotency-Key"] = Idempotency_Key; |
40 | } |
41 | if (Persona_Version) { |
42 | headers["Persona-Version"] = Persona_Version; |
43 | } |
44 | const response = await fetch(url, { |
45 | method: "POST", |
46 | headers, |
47 | body: JSON.stringify(body), |
48 | }); |
49 | if (!response.ok) { |
50 | const text = await response.text(); |
51 | throw new Error(`${response.status} ${text}`); |
52 | } |
53 | return await response.json(); |
54 | } |
55 |
|