Edits history of script submission #14432 for ' Get trashed folder (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * Get trashed folder
     * Retrieves a folder that has been moved to the trash.
    
    Please note that only if the folder itself has been moved to the
    trash can it be retrieved with this API call. If instead one of
    its parent folders was moved to the trash, only that folder
    can be inspected using the
    [`GET /folders/:id/trash`](e://get_folders_id_trash) API.
    
    To list all items that have been moved to the trash, please
    use the [`GET /folders/trash/items`](e://get-folders-trash-items/)
    API.
     */
    export async function main(
      auth: Box,
      folder_id: string,
      fields: string | undefined,
    ) {
      const url = new URL(`https://api.box.com/2.0/folders/${folder_id}/trash`);
      for (const [k, v] of [["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