Blocks-Endpoint Examples

Fetching Block

You can fetch specific blocks with the following statement:

# Fetches the content and information of a specific block
\Notion::block($blockId)
       ->retrieve();

If the returned block is a supported block from the Notion API, you will receive one of the classes described in ┬╗Supported Block Types┬ź. Otherwise you will receive the Block class.

Fetching Block Children

You can fetch the children of every block and page.

Just use the following statement:

# Fetches children from a specific block as a Collection
\Notion::block($blockId)
       ->limit(5) // limit is optional
       ->children()
       ->asCollection();


If you need to send fetched data over to the clientside or process it otherwise, you can fetch data as JSON.

# Fetches children from a specific block as JSON
\Notion::block($blockId)
       ->children()
       ->asJson();


So called unsupported_blocks (Notion API Docs) are ignored by default.

Include unsupported blocks with ->withUnsupported().

# Fetches children from a specific block as JSON
\Notion::block($blockId)
       ->children()
       ->withUnsupported()
       ->asCollection();


In some cases just the content representation of all blocks is needed.

It is possible to only get the blocks' content with ->asTextCollection().

# Fetches children from a specific block as a Collection of their content
\Notion::block($blockId)
       ->children()
       ->asTextCollection();

Block Types

All currently possible block classes are listed below.

BulletedListItem

ChildPage

HeadingOne

HeadingTwo

HeadingThree

NumberedListItem

Paragraph

TextBlock

ToDo

Toggle

Image

Embed

File

Video

Pdf


All unsupported or unrecognized blocks will be returned as Block.