Skip to main content

Method

client.search(args: SearchParameters): Promise<SearchResponse>

Parameters

query
string
The text that the API compares page and data source titles against.
filter
object
A filter to limit the results to pages or data sources.
sort
object
How to sort the results.
start_cursor
string
If supplied, this endpoint will return a page of results starting after the cursor provided. If not supplied, this endpoint will return the first page of results.
page_size
number
The number of items from the full list desired in the response. Maximum: 100.
auth
string
Bearer token for authentication. If not provided, the client-level auth is used.

Response

object
string
Always "list".
type
string
Always "page_or_data_source".
results
array
An array of Page objects or DataSource objects that match the search query.
next_cursor
string | null
A cursor to use in the next request to get the next page of results. If null, there are no more results.
has_more
boolean
Whether there are more results to fetch.

Example

const response = await client.search({
  query: "External tasks",
  filter: {
    property: "object",
    value: "page",
  },
  sort: {
    direction: "ascending",
    timestamp: "last_edited_time",
  },
})

console.log(response.results)

Pagination

Use the pagination helpers for easy iteration:
import { iteratePaginatedAPI } from "@notionhq/client"

for await (const result of iteratePaginatedAPI(
  client.search,
  { query: "Tasks" }
)) {
  console.log(result)
}

Build docs developers (and LLMs) love