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

    Function createPage

    • Function

      Creates a new page in Notion and optionally appends child blocks to it.

      Parameters

      • options: {
            data: {
                parent: Object;
                properties?: Object;
                icon?: Object;
                cover?: Object;
                children?: Object[];
            };
            client?: Object;
            apiCall?: Function;
            getPage?: Function;
            getResults?: Function;
            templateWaitMs?: number;
            onTemplatePageCreated?: Function;
            skipAutoAppendOnTemplate?: boolean;
        }

        The options for creating a page.

        • data: {
              parent: Object;
              properties?: Object;
              icon?: Object;
              cover?: Object;
              children?: Object[];
          }

          The data for creating the page.

          • parent: Object

            The parent of the page (must include data_source_id, page_id, or database_id (database_id is deprecated and will not work in databases with more than one data source)).

          • Optionalproperties?: Object

            The properties of the page.

          • Optionalicon?: Object

            The icon of the page.

          • Optionalcover?: Object

            The cover of the page.

          • Optionalchildren?: Object[]

            An array of child blocks to add to the page.

        • Optionalclient?: Object

          The Notion client object. Either this or apiCall must be provided.

        • OptionalapiCall?: Function

          A custom function for making API calls. Receives { type: 'create_page', data } as argument. Either this or client must be provided.

        • OptionalgetPage?: Function

          A function to extract the page data from the API response. Defaults to (response) => response.

        • OptionalgetResults?: Function

          A function to extract results from the API response when appending blocks. Defaults to (response) => response.results.

        • OptionaltemplateWaitMs?: number

          Milliseconds to wait after page creation when using templates, before appending children.

        • OptionalonTemplatePageCreated?: Function

          Optional callback function called after page creation but before appending children when using templates. Receives { page, template, fallbackWaitMs } as parameter, where page is the created Notion page object, template is the template object used to create the page, and fallbackWaitMs is the value of templateWaitMs. Can throw an error to stop execution and prevent children appending. Alternatively, you can pass a number to templateWaitMs, which the callback can use in case it fails to directly verify the template is ready.

        • OptionalskipAutoAppendOnTemplate?: boolean

          If true, returns children to caller instead of auto-appending them when using templates.

      Returns Promise<Object>

      An object containing the API response for page creation and, if applicable, the result of appending children. When skipAutoAppendOnTemplate is true and templates are used, returns { apiResponse, pendingChildren, pageId } instead.

      RequestShorthand

      If no parent is provided or if there's an error during page creation or block appending.

      // Using with Notion SDK client
      const notion = new Client({ auth: NOTION_TOKEN });
      const page = createNotion()
      .parentDataSource("your-data-source-id")
      .title("Name", "Charmander")
      .icon("https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/4.png")
      .richText("Category", "Lizard Pokémon")
      .quote("Obviously prefers hot places. When it rains, steam is said to spout from the tip of its tail.")
      .build()

      const result = await createPage({
      data: page.content,
      client: notion
      });

      // Using with custom API call function
      const apiCall = async ({ type, data }) => {
      if (type === 'create_page') {
      // Your custom API call implementation for page creation
      return await someHTTPClient.post('https://api.notion.com/v1/pages', { json: data });
      } else if (type === 'append_blocks') {
      // Your custom API call implementation for block appending
      const { block_id, children, after } = data;
      return await someHTTPClient.patch(`https://api.notion.com/v1/blocks/${block_id}/children`, {
      json: { children, ...(after && { after }) }
      });
      }
      };

      const result = await createPage({
      data: page.content,
      apiCall,
      getPage: (response) => response,
      getResults: (response) => response.results
      });