Edits history of script submission #14465 for ' List folder app item associations (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * List folder app item associations
     * **This is a beta feature, which means that its availability might be limited.**
    Returns all app items the folder is associated with. This includes app items
    associated with ancestors of the folder. Assuming the context user has access
    to the folder, the type/ids are revealed even if the context user does not
    have **View** permission on the app item.
     */
    export async function main(
      auth: Box,
      folder_id: string,
      limit: string | undefined,
      marker: string | undefined,
      application_type: string | undefined,
    ) {
      const url = new URL(
        `https://api.box.com/2.0/folders/${folder_id}/app_item_associations`,
      );
      for (const [k, v] of [
        ["limit", limit],
        ["marker", marker],
        ["application_type", application_type],
      ]) {
        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