Edits history of script submission #14481 for ' List retention policy assignments (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * List retention policy assignments
     * Returns a list of all retention policy assignments associated with a specified
    retention policy.
     */
    export async function main(
      auth: Box,
      retention_policy_id: string,
      type: "folder" | "enterprise" | "metadata_template" | undefined,
      fields: string | undefined,
      marker: string | undefined,
      limit: string | undefined,
    ) {
      const url = new URL(
        `https://api.box.com/2.0/retention_policies/${retention_policy_id}/assignments`,
      );
      for (const [k, v] of [
        ["type", type],
        ["fields", fields],
        ["marker", marker],
        ["limit", limit],
      ]) {
        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