Edits history of script submission #17336 for ' Get boards (miro)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Miro = {
      token: string;
    };
    /**
     * Get boards
     * Retrieves a list of boards accessible to the user associated with the provided access token.
     */
    export async function main(
      auth: Miro,
      team_id: string | undefined,
      project_id: string | undefined,
      query: string | undefined,
      owner: string | undefined,
      limit: string | undefined,
      offset: string | undefined,
      sort:
        | "default"
        | "last_modified"
        | "last_opened"
        | "last_created"
        | "alphabetically"
        | undefined,
    ) {
      const url = new URL(`https://api.miro.com//v2/boards`);
      for (const [k, v] of [
        ["team_id", team_id],
        ["project_id", project_id],
        ["query", query],
        ["owner", owner],
        ["limit", limit],
        ["offset", offset],
        ["sort", sort],
      ]) {
        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 235 days ago