Download the PHP package pi-space/notion-api-integration without Composer
On this page you can find all versions of the php package pi-space/notion-api-integration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pi-space/notion-api-integration
More information about pi-space/notion-api-integration
Files in pi-space/notion-api-integration
Package notion-api-integration
Short Description Easy to use and simple Integration to Notion API.
License MIT
Homepage https://github.com/eyadhamza/notion-api-wrapper
Informations about the package notion-api-integration
Laravel Notion Integration
About
The Laravel Notion Integration package is a wrapper for the REST API provided by Notion.so. It allows for easy interaction with your Notion workspace, saving you time and effort.
This package provides an easy and fluent interface for manipulating pages, databases, users, blocks, and more.
Installation
You can install the package via composer:
Usage
Setting Up Notion Workspace
In your .env
file, add your Notion token:
To create your first integration, please visit: Notion Create an integration To obtain your secret token, visit Notion API
Handling Notion Databases
Fetching Notion Database by ID
To fetch a Notion database by ID, use the find
method of the NotionDatabase
class. It will return a NotionDatabase
object containing information such as title, description, and all the database properties.
Creating a Notion Database
To create a Notion database, use the NotionDatabase
class and set the required parameters such as parent page ID and
properties schema.
Updating a Notion Database
To update an existing Notion database, use the NotionDatabase
class and specify the database ID and updated
properties.
Querying a Database
To query a Notion database and get a list of pages contained within the database, you can apply filters and sorting
criteria using the query
method.
Handling Notion Pages
Fetching a Page by ID (without the page contents)
Fetching a Page by ID (with the page contents)
Creating a New Notion Page / Notion Database Item
To create a new Notion page or a new item in a Notion database, you can use the NotionPage
class and set the required
properties and their values.
Creating a New Notion Page / Notion Database Item with Content
Updating a Page Properties
To update the properties of an existing page, create a NotionPage
object with the page ID, set the updated properties,
and call the update()
method.
Deleting a Page
To delete a page, create a NotionPage
object with the page ID and call the delete()
method.
Handling Notion Blocks
Fetching a Block by ID
To fetch a Notion block by ID, use the find
method of the NotionBlock
class.
Fetching Block Children
To fetch the children blocks of a Notion block, use the fetchChildren
method.
Updating a Block
To update a Notion block, create a new instance of the NotionBlock
class, set the updated content, and call
the update()
method.
Appending Block Children
To append children blocks to a Notion block, use the createChildren
method.
Deleting a Block
To delete a Notion block, use the delete
method.
Searching
You can perform searches in Notion pages or databases using the NotionSearch
class.
Searching in Pages
To search for a specific query in Notion pages, use the inPages
method of the NotionSearch
class. You can apply
sorting criteria using the sorts
method.
Searching in Databases
To search for a specific query in Notion databases, use the inDatabases
method of the NotionSearch
class.
Users
Retrieving All Users
To retrieve all Notion users, use the index
method of the NotionUser
class.
Retrieving a User by ID
To retrieve a specific Notion user by ID, use the find
method of the NotionUser
class.
Retrieving Current Bot Info
To retrieve information about the current Notion bot, use the getBot
method of the NotionUser
class.
Comments
Retrieving All Comments by Page ID / Discussion ID
To retrieve all comments associated with a page or discussion, use the index
method of the NotionComment
class.
Creating a New Comment
To create a new comment on a page or discussion, use the NotionComment
class and set the parent ID and content.
Pagination
Notion API provides paginated responses for certain endpoints. The NotionPaginator
class handles pagination for you.
Example with Search Results
Mapping Eloquent Models to Notion Database Items
To map your Laravel Eloquent models to Notion database items, you can use the Notionable
trait and implement
the mapToNotion
method in your model.
Syncing Data between Notion and Eloquent Models
You can sync data between Notion and Eloquent models using the sync:to-notion
Artisan command.
Watching a Notion Database
Currently, Notion API does not support webhooks. However, you can use the 'notion:watch' artisan command to watch a Notion database for changes. The command will run every specified interval and check for changes in the notion database. If there are any changes, it will send a post request to your route, so you can handle it accordingly. You can change the interval and the route in the config file.
This is how you can run the command:
Surely, you can use the command in a cron job to run it every specified interval.
Handling Errors
In case of an error, an exception will be thrown with the error message. You can check the exceptions folder or
the NotionException
class for more information about the exceptions. Please refer to the Notion API documentation for
detailed information about the errors.
Testing
To run the package tests, use the following command:
Changelog
Please see the CHANGELOG for more information on what has changed recently.
Contributing
Please
see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- EyadHamza
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of notion-api-integration with dependencies
guzzlehttp/guzzle Version ^7.7
illuminate/contracts Version ^10.0
spatie/laravel-package-tools Version ^1.14.0