PHP code example of jensvandewiel / laravel-notion-api

1. Go to this page and download the library: Download jensvandewiel/laravel-notion-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jensvandewiel / laravel-notion-api example snippets


use Jensvandewiel\LaravelNotionApi\Notion;

$notion = new Notion(env('NOTION_API_TOKEN'));

use Notion;

Notion::pages()->find('page_id');

$page = Notion::pages()->find('page_id');

$page = new Page();
$page->setTitle('Name', 'My New Page');
$page->setText('Description', 'This is a description');

$createdPage = Notion::pages()->createInDatabase('database_id', $page);

$page = new Page();
$page->setTitle('Name', 'My New Page');

$createdPage = Notion::pages()->createInPage('parent_page_id', $page);

$page = Notion::pages()->find('page_id');
$page->setTitle('Name', 'Updated Title');
$page->setText('Description', 'Updated description');

$updatedPage = Notion::pages()->update($page);

Notion::pages()->archive('page_id');

Notion::pages()->move('page_id', ['parent' => ['page_id' => 'new_parent_id']]);

$database = Notion::databases()->find('database_id');

$database = new Database();
// Set properties...

$createdDatabase = Notion::databases()->create($database);

$database = Notion::databases()->find('database_id');
// Modify properties...

$updatedDatabase = Notion::databases()->update($database);

$query = Notion::databases()->query('database_id');
$pages = $query->filter(['property' => 'Name', 'text' => ['contains' => 'search term']])->get();

$blocks = Notion::blocks()->getChildren('block_id');

$blocks = [
    ['type' => 'paragraph', 'paragraph' => ['rich_text' => [['type' => 'text', 'text' => ['content' => 'New paragraph']]]]]
];

Notion::blocks()->appendChildren('block_id', $blocks);

Notion::blocks()->update('block_id', ['type' => 'paragraph', 'paragraph' => ['rich_text' => [['type' => 'text', 'text' => ['content' => 'Updated content']]]]);

Notion::blocks()->delete('block_id');

Notion::comments()->create('page_id', 'Comment text');

$comments = Notion::comments()->list('page_id');

$users = Notion::users()->list();

$user = Notion::users()->find('user_id');

$results = Notion::search('query')->query()->asCollection();

$upload = Notion::fileUploads()->create('file_name', 'file_type');

Notion::fileUploads()->send($upload->getId(), $fileContent);

Notion::fileUploads()->complete($upload->getId());

$query = Notion::databases()->query('database_id');
$query->filter([
    'property' => 'Name',
    'text' => ['contains' => 'search']
]);
$query->sort([
    'property' => 'Created',
    'direction' => 'descending'
]);
$results = $query->get();

try {
    $page = Notion::pages()->find('page_id');
} catch (NotionException $e) {
    // Handle error
}
bash
   php artisan vendor:publish --provider="Jensvandewiel\LaravelNotionApi\LaravelNotionApiServiceProvider"