0

Perform Simulate Actions

by
Published Apr 8, 2025

Performs a series of simulated actions on a Sandbox Inquiry.

Script persona Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Persona = {
3
  apiKey: string;
4
};
5
/**
6
 * Perform Simulate Actions
7
 * Performs a series of simulated actions on a Sandbox Inquiry.
8
 */
9
export async function main(
10
  auth: Persona,
11
  inquiry_id: string,
12
  body: {
13
    meta: {
14
      "simulate-actions":
15
        | {
16
            type:
17
              | "start_inquiry"
18
              | "complete_inquiry"
19
              | "fail_inquiry"
20
              | "expire_inquiry"
21
              | "mark_for_review_inquiry"
22
              | "approve_inquiry"
23
              | "decline_inquiry";
24
          }
25
        | {
26
            type: "create_passed_verification" | "create_failed_verification";
27
            data: { "verification-template-id": string };
28
          }[];
29
    };
30
  },
31
  include: string | undefined,
32
  fields: string | undefined,
33
  Key_Inflection?: string,
34
  Idempotency_Key?: string,
35
  Persona_Version?: string,
36
) {
37
  const url = new URL(
38
    `https://api.withpersona.com/api/v1/inquiries/${inquiry_id}/perform-simulate-actions`,
39
  );
40
  for (const [k, v] of [
41
    ["include", include],
42
    ["fields", fields],
43
  ]) {
44
    if (v !== undefined && v !== "" && k !== undefined) {
45
      url.searchParams.append(k, 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