//native
/**
* Search
* Search the pages and data sources (databases) shared with the integration by title. Leave `query` empty to list everything. Paginate with `next_cursor` as `start_cursor`.
*/
export async function main(
auth: RT.Notion,
query: string | undefined,
object_type: "page" | "data_source" | undefined,
sort_direction: "ascending" | "descending" | undefined,
start_cursor: string | undefined,
page_size: number | undefined
) {
const body: { [key: string]: any } = {}
if (query !== undefined && query !== "") body.query = query
if (object_type) body.filter = { property: "object", value: object_type }
if (sort_direction) {
body.sort = { timestamp: "last_edited_time", direction: sort_direction }
}
if (start_cursor !== undefined && start_cursor !== "") {
body.start_cursor = start_cursor
}
if (page_size !== undefined) body.page_size = page_size
const response = await fetch("https://api.notion.com/v1/search", {
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
"Notion-Version": "2026-03-11",
},
body: JSON.stringify(body),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 4 hours ago