0

Expire an Inquiry

by
Published Apr 8, 2025

Expires an Inquiry and all sessions on the Inquiry. Cancels any pending Verifications on the inquiry. The Inquiry can still be resumed after expiry.

Script persona Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Persona = {
3
  apiKey: string;
4
};
5
/**
6
 * Expire an Inquiry
7
 * Expires an Inquiry and all sessions on the Inquiry. Cancels any pending Verifications on the inquiry.
8

9
The Inquiry can still be resumed after expiry.
10
 */
11
export async function main(
12
  auth: Persona,
13
  inquiry_id: 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}/expire`,
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
  };
34
  if (Key_Inflection) {
35
    headers["Key-Inflection"] = Key_Inflection;
36
  }
37
  if (Idempotency_Key) {
38
    headers["Idempotency-Key"] = Idempotency_Key;
39
  }
40
  if (Persona_Version) {
41
    headers["Persona-Version"] = Persona_Version;
42
  }
43
  const response = await fetch(url, {
44
    method: "POST",
45
    headers,
46
    body: undefined,
47
  });
48
  if (!response.ok) {
49
    const text = await response.text();
50
    throw new Error(`${response.status} ${text}`);
51
  }
52
  return await response.json();
53
}
54