Edits history of script submission #14480 for ' List retention policies (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * List retention policies
     * Retrieves all of the retention policies for an enterprise.
     */
    export async function main(
      auth: Box,
      policy_name: string | undefined,
      policy_type: "finite" | "indefinite" | undefined,
      created_by_user_id: string | undefined,
      fields: string | undefined,
      limit: string | undefined,
      marker: string | undefined,
    ) {
      const url = new URL(`https://api.box.com/2.0/retention_policies`);
      for (const [k, v] of [
        ["policy_name", policy_name],
        ["policy_type", policy_type],
        ["created_by_user_id", created_by_user_id],
        ["fields", fields],
        ["limit", limit],
        ["marker", marker],
      ]) {
        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