Edits history of script submission #14471 for ' List legal hold policy assignments (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * List legal hold policy assignments
     * Retrieves a list of items a legal hold policy has been assigned to.
     */
    export async function main(
      auth: Box,
      policy_id: string | undefined,
      assign_to_type: "file" | "file_version" | "folder" | "user" | undefined,
      assign_to_id: string | undefined,
      marker: string | undefined,
      limit: string | undefined,
      fields: string | undefined,
    ) {
      const url = new URL(`https://api.box.com/2.0/legal_hold_policy_assignments`);
      for (const [k, v] of [
        ["policy_id", policy_id],
        ["assign_to_type", assign_to_type],
        ["assign_to_id", assign_to_id],
        ["marker", marker],
        ["limit", limit],
        ["fields", fields],
      ]) {
        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