CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-notionhq--client

A simple and easy to use client for the Notion API

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

search.mddocs/

Search

Search across the entire Notion workspace for pages, databases, and other content.

Capabilities

Search Workspace

Search for pages and databases across the entire Notion workspace with optional filtering and sorting.

/**
 * Search across the Notion workspace
 * @param args - Search parameters including query and filters
 * @returns Promise resolving to search results
 */
search(args: SearchParameters): Promise<SearchResponse>;

interface SearchParameters {
  /** Search query text */
  query?: string;
  /** Sort criteria for results */
  sort?: {
    direction: "ascending" | "descending";
    timestamp: "last_edited_time";
  };
  /** Filter results by object type */
  filter?: {
    value: "page" | "database";
    property: "object";
  };
  /** Pagination cursor */
  start_cursor?: string;
  /** Page size (max 100) */
  page_size?: number;
}

type SearchResponse = {
  object: "list";
  results: (PageObjectResponse | DatabaseObjectResponse)[];
  next_cursor: string | null;
  has_more: boolean;
  type: "page_or_database";
  page_or_database: Record<string, unknown>;
};

Usage Examples:

// Basic search
const results = await notion.search({
  query: "project management",
});

console.log(`Found ${results.results.length} results`);
results.results.forEach(result => {
  if (result.object === "page") {
    console.log(`Page: ${result.properties.title?.title?.[0]?.text?.content}`);
  } else if (result.object === "database") {
    console.log(`Database: ${result.title?.[0]?.text?.content}`);
  }
});

// Search with filters
const pageResults = await notion.search({
  query: "meeting notes",
  filter: {
    value: "page",
    property: "object",
  },
  sort: {
    direction: "descending",
    timestamp: "last_edited_time",
  },
});

// Search databases only
const databaseResults = await notion.search({
  filter: {
    value: "database",
    property: "object",
  },
  sort: {
    direction: "ascending",
    timestamp: "last_edited_time",
  },
});

// Paginated search
const searchPage = await notion.search({
  query: "tasks",
  page_size: 50,
  start_cursor: "cursor-token",
});

// Search all content with pagination
let cursor: string | undefined;
let allResults: (PageObjectResponse | DatabaseObjectResponse)[] = [];

do {
  const response = await notion.search({
    query: "important",
    start_cursor: cursor,
  });
  
  allResults.push(...response.results);
  cursor = response.next_cursor || undefined;
} while (cursor);

// Search without query (get all accessible content)
const allContent = await notion.search({
  sort: {
    direction: "descending",
    timestamp: "last_edited_time",
  },
});

Search Best Practices

// Search for specific content types
async function findProjectDatabases() {
  return await notion.search({
    query: "project",
    filter: {
      value: "database",
      property: "object",
    },
  });
}

// Recent content search
async function getRecentContent(days: number = 7) {
  const results = await notion.search({
    sort: {
      direction: "descending",
      timestamp: "last_edited_time",
    },
  });
  
  const cutoffDate = new Date();
  cutoffDate.setDate(cutoffDate.getDate() - days);
  
  return results.results.filter(result => {
    const lastEdited = new Date(result.last_edited_time);
    return lastEdited >= cutoffDate;
  });
}

// Find pages by title pattern
async function findPagesByTitle(titlePattern: string) {
  const results = await notion.search({
    query: titlePattern,
    filter: {
      value: "page",
      property: "object",
    },
  });
  
  return results.results.filter(result => {
    if (result.object === "page") {
      const title = result.properties.title?.title?.[0]?.text?.content || "";
      return title.toLowerCase().includes(titlePattern.toLowerCase());
    }
    return false;
  });
}

Types

interface SearchParameters {
  /** Search query text */
  query?: string;
  /** Sort criteria for results */
  sort?: {
    direction: "ascending" | "descending";
    timestamp: "last_edited_time";
  };
  /** Filter results by object type */
  filter?: {
    value: "page" | "database";
    property: "object";
  };
  /** Pagination cursor */
  start_cursor?: string;
  /** Page size (max 100) */
  page_size?: number;
}

interface SearchResponse {
  object: "list";
  results: (PageObjectResponse | DatabaseObjectResponse)[];
  next_cursor: string | null;
  has_more: boolean;
  type: "page_or_database";
  page_or_database: Record<string, unknown>;
}

Install with Tessl CLI

npx tessl i tessl/npm-notionhq--client

docs

block-operations.md

client-configuration.md

comments.md

data-source-operations.md

database-operations.md

error-handling.md

file-uploads.md

index.md

oauth-authentication.md

page-operations.md

pagination-helpers.md

search.md

user-management.md

tile.json