Notion Helper - v1.3.29
    Preparing search index...

    Function createNotionBuilder

    • Function

      Creates a fluent interface builder for constructing Notion objects, including pages, properties, and blocks.

      Fluent Interface Methods:

      The returned builder provides chainable methods organized into categories:

      Page Setup Methods:

      • parentDataSource(data_source_id) - Sets parent data source
      • parentDs(data_source_id) - Alias for parentDataSource()
      • parentPage(page_id) - Sets parent page
      • parentDatabase(database_id) - Sets parent database (deprecated, will not work in databases with more than one data source)
      • parentDb(database_id) - Alias for parentDatabase() (deprecated, will not work in databases with more than one data source)
      • pageId(page_id) - Adds page ID for updates
      • blockId(block_id) - Adds block ID for block operations
      • propertyId(property_id) - Adds property ID for property operations
      • cover(url) - Sets page cover image
      • icon(url) - Sets page icon

      Property Methods:

      • property(name, type, value) - Adds custom property
      • title(name, value) - Adds title property
      • richText(name, value) - Adds rich text property
      • checkbox(name, value) - Adds checkbox property
      • date(name, value) - Adds date property
      • email(name, value) - Adds email property
      • files(name, value) - Adds files property
      • multiSelect(name, value) - Adds multi-select property
      • number(name, value) - Adds number property
      • people(name, value) - Adds people property
      • phoneNumber(name, value) - Adds phone number property
      • relation(name, value) - Adds relation property
      • select(name, value) - Adds select property
      • status(name, value) - Adds status property
      • url(name, value) - Adds URL property

      Block Methods:

      • paragraph(content, options, url) - Adds paragraph block
      • heading1(content, options, url) - Adds H1 block
      • heading2(content, options, url) - Adds H2 block
      • heading3(content, options, url) - Adds H3 block
      • bulletedListItem(content, options, url) - Adds bulleted list item
      • numberedListItem(content, options, url) - Adds numbered list item
      • toDo(content, checked, options, url) - Adds to-do block
      • callout(content, emoji, options, url) - Adds callout block
      • quote(content, options, url) - Adds quote block
      • code(content, language) - Adds code block
      • divider() - Adds divider block
      • image(url, caption) - Adds image block
      • video(url, caption) - Adds video block
      • audio(url, caption) - Adds audio block
      • file(url, caption) - Adds file block
      • pdf(url, caption) - Adds PDF block
      • bookmark(url, caption) - Adds bookmark block
      • embed(url, caption) - Adds embed block
      • table(tableArray) - Adds table block
      • tableRow(cellContents) - Adds table row
      • columnList(columnArray) - Adds column list
      • column(columnContent) - Adds column
      • toggle(content, children, options, url) - Adds toggle block

      Structure Management:

      • startParent(parentBlock) - Begins nested block structure
      • endParent() - Ends current nesting level
      • build() - Finalizes and returns the built object

      Return Object:

      Returns an object with two possible properties:

      • content (always returned) - can be a full page object, an array of blocks, or a properties object
      • additionalBlocks - array containing block chunks that exceed Notion's limits for subsequent requests

      createNotionBuilder

      Parameters

      • Optionaloptions: {
            strict?: boolean;
            limitNesting?: boolean;
            limitChildren?: boolean;
            allowBlankParagraphs?: boolean;
            handleTemplatePageChildren?: boolean;
        } = {}

        Configuration options for the builder

        • Optionalstrict?: boolean

          If true, throws errors for invalid data. Otherwise gracefully handles nulls.

        • OptionallimitNesting?: boolean

          If true, limits nested children to 2 levels (Notion API limit).

        • OptionallimitChildren?: boolean

          If true, limits children arrays to 100 blocks, putting excess in additionalBlocks.

        • OptionalallowBlankParagraphs?: boolean

          If true, allows empty paragraph blocks.

        • OptionalhandleTemplatePageChildren?: boolean

          If true, automatically moves all children blocks to additionalBlocks when a template is applied (type is not "none"). This is required because the Notion API doesn't allow children blocks in page creation requests that apply templates.

      Returns Object

      A builder object with fluent interface methods for constructing Notion content.

      // Basic page creation
      const page = createNotionBuilder()
      .parentDataSource('data-source-id')
      .title('Name', 'My Task')
      .select('Status', 'In Progress')
      .date('Due Date', '2024-12-01')
      .paragraph('This is a task description.')
      .toDo('Complete the first step', false)
      .toDo('Review with team', false)
      .build();

      // Complex nested structure
      const complexPage = createNotionBuilder()
      .parentDataSource('data-source-id')
      .title('Project Name', 'Website Redesign')
      .heading1('Project Overview')
      .paragraph('This project involves redesigning our main website.')
      .heading2('Phase 1: Research')
      .startParent(toggle('Research Tasks', []))
      .toDo('Conduct user interviews', false)
      .toDo('Analyze competitor websites', false)
      .endParent()
      .heading2('Phase 2: Design')
      .callout('Important: Get stakeholder approval before development', '⚠️')
      .build();

      // Handle large content with additionalBlocks
      const result = page.content;
      const extraBlocks = page.additionalBlocks;

      // Create page first, then append additional blocks if needed
      const notion = new Client({ auth: process.env.NOTION_TOKEN });
      const newPage = await notion.pages.create(result);

      if (extraBlocks && extraBlocks.length > 0) {
      for (const blockChunk of extraBlocks) {
      await notion.blocks.children.append({
      block_id: newPage.id,
      children: blockChunk
      });
      }
      }

      // Using template with automatic children handling
      const templatePage = createNotionBuilder({ handleTemplatePageChildren: true })
      .parentDataSource('data-source-id')
      .template('default') // or template_id
      .title('Name', 'Task from Template')
      .paragraph('This content will be moved to additionalBlocks')
      .toDo('Complete task', false)
      .build();

      // Create page with template, then append children
      const notion = new Client({ auth: process.env.NOTION_TOKEN });
      const newPage = await notion.pages.create(templatePage.content);

      // Append the children that were moved to additionalBlocks
      if (templatePage.additionalBlocks && templatePage.additionalBlocks.length > 0) {
      for (const blockChunk of templatePage.additionalBlocks) {
      await notion.blocks.children.append({
      block_id: newPage.id,
      children: blockChunk
      });
      }
      }