You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,6 +113,20 @@ The `Client` supports the following options on initialization. These options can
113
113
|`baseUrl`|`"https://api.notion.com"`|`string`| The root URL for sending API requests. This can be changed to test with a mock server. |
114
114
|`httpClient`| Default Http Client |`Psr\Http\Client\ClientInterface`| The Http Client used to make request on the Notion API. This can be change to customize the base Http Client or replace with a mocked Http Client. |
115
115
116
+
## Examples
117
+
118
+
The `examples/` directory contains a comprehensive set of usage examples that demonstrate how to use the SDK for various tasks, from basic API calls to complex integrations:
119
+
120
+
-**[01-intro-to-notion-api](examples/01-intro-to-notion-api/)** - Basic database queries and page creation
121
+
-**[02-parse-text-from-any-block](examples/02-parse-text-from-any-block/)** - Extract text content from all block types
122
+
-**[03-web-form](examples/03-web-form/)** - Web form to Notion page integration
123
+
-**[04-generate-random-data](examples/04-generate-random-data/)** - Populate databases with sample data
124
+
-**[05-notify-on-update](examples/05-notify-on-update/)** - Email notifications for database changes
This example demonstrates how to use the `notion-sdk-php` to recursively fetch all blocks on a page and extract their complete text content. This is useful for tasks like indexing page content for search.
4
+
5
+
The script handles pagination and nested blocks (like toggles or columns) to ensure all text is extracted.
6
+
7
+
## Prerequisites
8
+
9
+
- PHP 7.4 or higher
10
+
- Composer
11
+
- Notion Integration Token
12
+
- Notion Page shared with your integration
13
+
14
+
## Setup
15
+
16
+
### 1. Install Dependencies
17
+
18
+
Navigate to this directory and install the required packages using Composer:
19
+
20
+
```bash
21
+
cd examples/02-parse-text-from-any-block
22
+
composer install
23
+
```
24
+
25
+
### 2. Environment Configuration
26
+
27
+
Create a `.env` file by copying the example file:
28
+
29
+
```bash
30
+
cp .env.example .env
31
+
```
32
+
33
+
Open the `.env` file and add your Notion integration token and page ID:
34
+
35
+
```dotenv
36
+
NOTION_TOKEN="secret_..."
37
+
NOTION_PAGE_ID="..."
38
+
```
39
+
40
+
## Usage
41
+
42
+
Execute the script from your terminal:
43
+
44
+
```bash
45
+
php index.php
46
+
```
47
+
48
+
The script will:
49
+
- Connect to your Notion workspace
50
+
- Recursively fetch all blocks from the specified page
0 commit comments