This example demonstrates how to populate a Notion database with randomly generated sample data using the notion-sdk-php. It's particularly useful for testing, development, and demonstrating various Notion property types.
The script automatically detects the database schema and generates appropriate random data for each property type.
- PHP 7.4 or higher
- Composer
- Notion Integration Token
- Notion Database shared with your integration (can be empty or with existing schema)
Navigate to this directory and install the required packages using Composer:
cd examples/04-generate-random-data
composer installCreate a .env file by copying the example file:
cp .env.example .envOpen the .env file and add your Notion integration token and database ID:
NOTION_TOKEN="secret_..."
NOTION_DATABASE_ID="..."Generate 10 random entries (default):
php index.phpGenerate a specific number of entries:
php index.php 50Or use the composer script:
composer generateThe script can generate data for the following Notion property types:
- Title: Company names, project titles
- Rich Text: Descriptions, comments
- Number: Quantities, scores, prices
- Select: Status, priority, category
- Multi-select: Tags, skills, departments
- Date: Deadlines, created dates
- Checkbox: Boolean values
- Email: Fake email addresses
- Phone: Fake phone numbers
- URL: Fake website URLs
- Automatic database schema detection
- Progress updates during generation
- Batch processing for better performance
- Error handling with informative messages
- Realistic, contextual fake data using Faker library
- Support for any database structure
Notion SDK PHP - Random Data Generator
=====================================
Analyzing database schema...
Found 5 properties: Name (title), Email (email), Status (select), Created (date), Active (checkbox)
Generating 10 random entries...
Progress: [██████████] 10/10 (100%)
Successfully created 10 entries in your Notion database!