Edits history of script submission #14536 for ' Search for content (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * Search for content
     * Searches for files, folders, web links, and shared files across the
    users content or across the entire enterprise.
     */
    export async function main(
      auth: Box,
      query: string | undefined,
      scope: "user_content" | "enterprise_content" | undefined,
      file_extensions: string | undefined,
      created_at_range: string | undefined,
      updated_at_range: string | undefined,
      size_range: string | undefined,
      owner_user_ids: string | undefined,
      recent_updater_user_ids: string | undefined,
      ancestor_folder_ids: string | undefined,
      content_types: string | undefined,
      type: "file" | "folder" | "web_link" | undefined,
      trash_content: "non_trashed_only" | "trashed_only" | "all_items" | undefined,
      mdfilters: string | undefined,
      sort: "modified_at" | "relevance" | undefined,
      direction: "DESC" | "ASC" | undefined,
      limit: string | undefined,
      include_recent_shared_links: string | undefined,
      fields: string | undefined,
      offset: string | undefined,
      deleted_user_ids: string | undefined,
      deleted_at_range: string | undefined,
    ) {
      const url = new URL(`https://api.box.com/2.0/search`);
      for (const [k, v] of [
        ["query", query],
        ["scope", scope],
        ["file_extensions", file_extensions],
        ["created_at_range", created_at_range],
        ["updated_at_range", updated_at_range],
        ["size_range", size_range],
        ["owner_user_ids", owner_user_ids],
        ["recent_updater_user_ids", recent_updater_user_ids],
        ["ancestor_folder_ids", ancestor_folder_ids],
        ["content_types", content_types],
        ["type", type],
        ["trash_content", trash_content],
        ["mdfilters", mdfilters],
        ["sort", sort],
        ["direction", direction],
        ["limit", limit],
        ["include_recent_shared_links", include_recent_shared_links],
        ["fields", fields],
        ["offset", offset],
        ["deleted_user_ids", deleted_user_ids],
        ["deleted_at_range", deleted_at_range],
      ]) {
        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