Download the PHP package jensvandewiel/laravel-notion-api without Composer
On this page you can find all versions of the php package jensvandewiel/laravel-notion-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jensvandewiel/laravel-notion-api
More information about jensvandewiel/laravel-notion-api
Files in jensvandewiel/laravel-notion-api
Package laravel-notion-api
Short Description Laravel Wrapper for the Notion API
License MIT
Homepage https://github.com/JensvandeWiel/laravel-notion-api
Informations about the package laravel-notion-api
Laravel Notion API Package
This package provides an elegant and comprehensive interface for interacting with the Notion API within Laravel applications. It allows you to query, create, update, and manage Notion pages, databases, blocks, comments, users, and more, with a fluent and intuitive API.
Note: This package is a fork maintained for stability and bug fixes on-demand. Updates and improvements are applied as needed, and tests are currently not fully correct. For the latest features, consider the original package.
Installation
The package is compatible with Laravel 12+. Support is only provided for Laravel 12 and above. The minimum PHP requirement is 8.0.
-
Install the package via Composer:
-
Obtain your Notion API access token by following the instructions in the Notion developer documentation at https://developers.notion.com/reference/authentication.
-
Add the token to your application's .env file:
- Publish the configuration file (optional, for customization):
Configuration
The package uses the NOTION_API_TOKEN environment variable for authentication. You can customize the API version and other settings in the published config file.
Basic Usage
Access Notion endpoints through the Notion facade:
Or use the facade:
Entities
The package provides several entity classes that represent Notion objects:
- Page: Represents a Notion page
- Database: Represents a Notion database
- DataSource: Represents a Notion data source
- Block: Represents a Notion block
- User: Represents a Notion user
- Comment: Represents a Notion comment
- FileUpload: Represents a file upload
- Token: Represents an OAuth token
- NotionParent: Represents parent relationships
Each entity provides methods to access and manipulate its properties.
Pages
Retrieving a Page
To retrieve a page by its ID:
This returns a Page entity with all its properties and content.
Creating a Page in a Database
To create a new page in a database:
Creating a Page as a Child of Another Page
Updating a Page
To update an existing page:
Archiving a Page
Moving a Page
Databases
Retrieving a Database
Creating a Database
Updating a Database
Querying a Database
Blocks
Retrieving Block Children
Appending Block Children
Updating a Block
Deleting a Block
Comments
Creating a Comment
Retrieving Comments
Users
Retrieving Users
Retrieving a Specific User
Search
Searching
File Uploads
Creating a File Upload
Sending a File Upload
Completing a File Upload
Property Types
The package supports all Notion property types:
- Title: setTitle('property_name', 'text')
- Rich Text: setText('property_name', 'text')
- Number: setNumber('property_name', 123.45)
- Select: setSelect('property_name', 'option_name')
- Multi-Select: setMultiSelect('property_name', ['option1', 'option2'])
- Date: setDate('property_name', $startDate, $endDate)
- People: setPeople('property_name', ['user_id1', 'user_id2'])
- Files: (handled via file uploads)
- Checkbox: setCheckbox('property_name', true)
- URL: setUrl('property_name', 'https://example.com')
- Email: setEmail('property_name', '[email protected]')
- Phone Number: setPhoneNumber('property_name', '123-456-7890')
- Relation: setRelation('property_name', ['page_id1', 'page_id2'])
- Place: setPlace('property_name', 'Location Name', 12.34, 56.78, 'Address')
Filtering and Sorting
When querying databases, you can apply filters and sorting:
Error Handling
The package throws NotionException for API errors. Always wrap your calls in try-catch blocks:
Advanced Usage
Working with Rich Text
Rich text is handled automatically for title and text properties. For more complex rich text manipulation, use the RichText entity.
Custom Property Types
For unsupported property types, you can extend the Property class and implement the Modifiable interface.
Batch Operations
For bulk operations, collect multiple requests and execute them in sequence.
Contributing
Contributions are welcome. Please ensure all tests pass and follow the existing code style.
License
This package is open-sourced software licensed under the MIT license.
All versions of laravel-notion-api with dependencies
guzzlehttp/guzzle Version ^7.0.1
illuminate/support Version ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0