Edits history of script submission #12897 for ' Print Report PDF (persona)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Persona = {
      apiKey: string;
    };
    /**
     * Print Report PDF
     * Prints a report in PDF format.
     */
    export async function main(
      auth: Persona,
      report_id: string,
      Key_Inflection?: string,
      Idempotency_Key?: string,
      Persona_Version?: string,
    ) {
      const url = new URL(
        `https://api.withpersona.com/api/v1/reports/${report_id}/print`,
      );
      const headers: Record<string, string> = {
        Authorization: `Bearer ${auth.apiKey}`,
      };
      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: "GET",
        headers,
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 428 days ago