Picture of the author

Notion Pages

Create and Modify Pages

Create new Notion Pages

Within a Page

Creating new pages within other pages cannot have custom Properties.

use FiveamCode\LaravelNotionApi\Entities\Properties\Title;

# This has to be a valid uuid of the parent Notion Page
$parentPageId = 'f7a7c7f7-7f7f-7f7f-7f7f-7f7f7f7f7f7f';

# Create the page and set the title
$page = new Page();
$page->set('title', Title::value('I was created from Laravel'));

Notion::pages()->createInPage($parentPageId, $page);

Within a Database

Pages within databases can have custom properties, which have to match the database structure.

If a property is not set, it will be set to the default value of the database, which will be empty in most cases.

use FiveamCode\LaravelNotionApi\Entities\Properties\Title;

# This has to be a valid uuid of a Notion Page
$parentDatabaseId = 'f7a7c7f7-7f7f-7f7f-7f7f-7f7f7f7f7f7f';

# Create the Page and set the Title
$page = new Page();
$page->set('title', Title::value('I was created from Laravel'));

# [...] setting properties

Notion::pages()->createInDatabase($parentDatabaseId, $page);

Setting Properties

Creating valid properties is fully described in Handling Properties .

Everything unique to Pages is described below.

Aside from the ::value approach described in the Handling Properties section, there is an alternative.

use FiveamCode\LaravelNotionApi\Entities\Properties\Title;

$page = new Page();

# Basic way of setting Properties
$page->set('title', Title::value('I was created from Laravel'));

# Alternative to ::value
$page->setTitle('title', 'I was created by you');

Notion::pages()->createInDatabase($databaseId, $page);

All supported properties can be set this alternative way.

Update Notion Pages

The process of updating pages is mostly the same as creating Pages.

The only difference is that you have to provide the page UUID of the page you want to update.

In case you have retrieved a page object, you can use it for updating the page without manually setting the ID.

use FiveamCode\LaravelNotionApi\Entities\Properties\Title;

# Create the Page and set the ID 
$page = new Page();
$page->setId($pageId);

# [...] setting properties

Notion::pages()->update($page);
Previous
Handle Properties