Edits history of script submission #12127 for ' Get activity logs (figma)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Figma = {
      token: string;
    };
    /**
     * Get activity logs
     * Returns a list of activity log events
     */
    export async function main(
      auth: Figma,
      events: string | undefined,
      start_time: string | undefined,
      end_time: string | undefined,
      limit: string | undefined,
      order: "asc" | "desc" | undefined,
    ) {
      const url = new URL(`https://api.figma.com/v1/activity_logs`);
      for (const [k, v] of [
        ["events", events],
        ["start_time", start_time],
        ["end_time", end_time],
        ["limit", limit],
        ["order", order],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago