Edits history of script submission #12895 for ' Perform Simulate Actions (persona)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Persona = {
      apiKey: string;
    };
    /**
     * Perform Simulate Actions
     * Performs a series of simulated actions on a Sandbox Inquiry.
     */
    export async function main(
      auth: Persona,
      inquiry_id: string,
      body: {
        meta: {
          "simulate-actions":
            | {
                type:
                  | "start_inquiry"
                  | "complete_inquiry"
                  | "fail_inquiry"
                  | "expire_inquiry"
                  | "mark_for_review_inquiry"
                  | "approve_inquiry"
                  | "decline_inquiry";
              }
            | {
                type: "create_passed_verification" | "create_failed_verification";
                data: { "verification-template-id": string };
              }[];
        };
      },
      include: string | undefined,
      fields: string | undefined,
      Key_Inflection?: string,
      Idempotency_Key?: string,
      Persona_Version?: string,
    ) {
      const url = new URL(
        `https://api.withpersona.com/api/v1/inquiries/${inquiry_id}/perform-simulate-actions`,
      );
      for (const [k, v] of [
        ["include", include],
        ["fields", fields],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const headers: Record<string, string> = {
        Authorization: `Bearer ${auth.apiKey}`,
        "Content-Type": "application/json",
      };
      if (Key_Inflection) {
        headers["Key-Inflection"] = Key_Inflection;
      }
      if (Idempotency_Key) {
        headers["Idempotency-Key"] = Idempotency_Key;
      }
      if (Persona_Version) {
        headers["Persona-Version"] = Persona_Version;
      }
      const response = await fetch(url, {
        method: "POST",
        headers,
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago