0

Approve an Inquiry

by
Published Apr 8, 2025

Approves an >. Note that this action will trigger any associated workflows and webhooks.

Script persona Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Persona = {
3
  apiKey: string;
4
};
5
/**
6
 * Approve an Inquiry
7
 * Approves an >.
8

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