Skip to contentnotionic
Docs menu

Reference

Fetch functions

fetchBlocks and fetchPage, from notionic/fetch.

TypeScript
import { fetchBlocks, fetchPage, fetchLinkFavicon } from "notionic/fetch"

fetchBlocks(client, blockId, options?)

Returns Promise<NotionBlock[]>: every block under blockId, with nested blocks as children, linked pages and subpages as linkedPage, previews of the pages behind bookmarks, embeds and link previews as bookmarkPreview, previews of the pages behind resource links as resourcePreview, and, with linkFavicons, the favicons of the sites its text links to as linkFavicons, by host.

fetchPage(client, pageId, options?)

Returns Promise<{ page: NotionPage; blocks: NotionBlock[] }>. page has id, url, title, icon, cover, lastEditedTime and properties.

Options

OptionDefaultDescription
maxDepth5Levels of nested blocks to fetch below the top level.
concurrency3Requests in flight at once per level.
bookmarkPreviewstrueFetch the page behind each bookmark, embed and link preview for its title, description, image and favicon, so they render as cards. false makes no requests outside Notion.
resources{ headings: ["Resources"] }The Resources section, as in NotionRenderer: the page behind each of its links is fetched for its favicon and description, unless bookmarkPreviews is false. Pass it only to rename the heading. See Untitled.
linkFaviconsfalseFetch the favicon of each site linked from text, from Google's favicon service and then DuckDuckGo's, and attach it as a data URL, for &lt;NotionRenderer linkFavicons&gt;. Pass { siteIcons: true } to read each site's own icon first. See Fetching pages (opens in a new tab). Each host is looked up once per call; a subdomain without one gets its site's. A site with none is recorded as null (a globe); a host the services couldn't answer for is left out, so the next fetch asks again. Private hosts are never sent.

fetchLinkFavicon(host, options?)

Returns Promise<string | null>: a site's favicon as a data URL, as linkFavicons fetches it, or null when it has none or the services couldn't answer. Pass { siteIcons: true } to try the site's own icon first. Private hosts get null without a request. It doesn't cache.

The client

client is a Client from @notionhq/client, or anything with the same blocks.children.list and pages.retrieve methods. Without pages.retrieve, fetchBlocks still works, but link to page blocks get no titles and subpages no icons.