A complete Notion SDK for PHP developers.

Overview

Codecov Type coverage Notion API version

notion-sdk-php

A complete Notion SDK for PHP developers.

Installation

composer require mariosimao/notion-php

Getting started

A Notion token will be needed to fully use this library. If you don't have one, please refer to Authorization section from the Notion API documentation.

A simple example on how to create a page with some content:

withTitle("Sample page") ->withIcon("⭐"); $content = Paragraph::fromString("This is a simple paragraph."); $client->pages()->create($page, $content); ">


use Notion\Client;
use Notion\Blocks\Paragraph;
use Notion\Pages\Page;
use Notion\Pages\PageParent;

$token = getenv("NOTION_TOKEN");
$client = Client::create($token);

$parent = PageParent::page("c986d7b0-7051-4f18-b165-cc0b9503ffc2");
$page = Page::create($parent)
            ->withTitle("Sample page")
            ->withIcon("⭐");

$content = Paragraph::fromString("This is a simple paragraph.");

$client->pages()->create($page, $content);

Documentation

Further documentation can be found here.

Comments
  • Internal cover image is not supported

    Internal cover image is not supported

    Internal cover images are now supported by Notion API, as read-only fields. I think we should be able to retrieve pages with internal covers instead of throwing an exception.

    opened by frederichoule 8
  • Add URL support to RichText objects

    Add URL support to RichText objects

    This PR intends to fix #88 by adding the ability to create RichText objects with URLs.

    This approach isn't exactly pure and effectively requires RichText to be a superset of Text, i.e. support everything that Text supports. An alternative might be to allow RichText::createText(string $content) to also support Text objects, hence allowing RichText to be created from string or Text.

    opened by NFarrington 4
  • No support for Status type in Database

    No support for Status type in Database

    Fatal error: Uncaught Exception: Invalid property type: 'status' in .../mariosimao/notion-sdk-php/src/Databases/Properties/Factory.php:34 Stack trace: #0

    Type:

    "Status": { "id": "xxx", "type": "status", "status": { "id": "xxx", "name": "Accepted", "color": "green" } }

    duplicate 
    opened by simondotws 3
  • How to retrieve pages from database

    How to retrieve pages from database

    Does this API allow for the ability to return a set of pages from a given database? I can't seem to find any documentation or tests that handle this use-case. Perhaps I'm missing something?

    opened by lewsid 3
  • Add mutation testing

    Add mutation testing

    As discussed here: https://github.com/mariosimao/notion-sdk-php/pull/6#discussion_r745935923

    Some comments inline in the diff.

    It includes fixing some mutations which were all the same thing so I could check out how it worked etc. I'd be happy to split those off to a separate pull request if preferred.

    opened by WillGibson 3
  • How to change the value of a property in a database row?

    How to change the value of a property in a database row?

    Hello, tell me what is the correct way to change the value of a property in a row from a database table? And yet, you can show an example of how to add new rows to a table with a data base.

    There are no examples at all of how to change property values in pages. Or I didn't find it.

    Thanks a lot. I hope you have some time to answer this question.

    And thanks a lot for this SDK.

    opened by ooomytech 2
  • fix: handle empty value for select property

    fix: handle empty value for select property

    If the a select property is empty the

    Notion\Pages\Properties\Option::fromArray(): Argument #1 ($array) must be of type array, null given, called in /vendor/mariosimao/notion-sdk-php/src/Pages/Properties/Select.php on line 49
    
    opened by iamalexchip 2
  • I need help to understand

    I need help to understand

    Hi there ! I start in php and I try to make the "sdk" work but I can't install it. Indeed I am word for word the doc but when executing the command I have this error:

    image

    Can anyone help me understand or have an example for me?

    Thanks in advance

    documentation help wanted 
    opened by yppdr 1
  • Issue with files field

    Issue with files field

    I have files property (Files & Media type)

    Screenshot 2022-08-19 at 20 31 18

    when I'm fetching my page

    $page = $notion->pages()->find('f3b4ab7c34fa4b71acb0c7fa011374d9');
    dd($page);
    

    I see error

    Fatal error: Uncaught Exception: Invalid property type: 'files' in /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/vendor/mariosimao/notion-sdk-php/src/Pages/Properties/Factory.php:34 Stack trace: #0 /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/vendor/mariosimao/notion-sdk-php/src/Pages/Page.php(108): Notion\Pages\Properties\Factory::fromArray(Array) #1 /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/vendor/mariosimao/notion-sdk-php/src/Pages/Client.php(57): Notion\Pages\Page::fromArray(Array) #2 /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/plugin.php(58): Notion\Pages\Client->find('f3b4ab7c34fa4b7...') #3 /Applications/MAMP/htdocs/projects/flextype/flextype/src/flextype/core/Plugins.php(423): require_once('/Applications/M...') #4 /Applications/MAMP/htdocs/projects/flextype/flextype/src/flextype/core/Plugins.php(191): Flextype\Plugins->includeEnabledPlugins() #5 /Applications/MAMP/htdocs/projects/flextype/flextype/src/flextype/core/Plugins.php(51): Flextype\Plugins->init() #6 /Applications/MAMP/htdocs/projects/flextype/flextype/src/flextype/flextype.php(350): Flextype\Plugins->__construct() #7 /Applications/MAMP/htdocs/projects/flextype/flextype/index.php(46): require_once('/Applications/M...') #8 {main} thrown in /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/vendor/mariosimao/notion-sdk-php/src/Pages/Properties/Factory.php on line 34
    
    opened by Awilum 1
  • Unable to create RichText URL

    Unable to create RichText URL

    Hello, thanks for the great SDK 😁

    It doesn't currently appear possible to create a RichText object with a link to a URL that's correctly formatted as a clickable link.

    As an example, I currently have this code:

    BulletedListItem::create()->withText([
        RichText::createText("My link: "),
        RichText::createText("https://example.com/my-link"),
    ]));
    

    It's not possible to use a Text object directly as BulletedListItem only accepts RichText. https://example.com/my-link isn't clickable in Notion, I guess because the underlying text object isn't a link object (https://developers.notion.com/reference/rich-text#link-objects).

    It would be great to be able to do something like the following to make the link clickable:

    BulletedListItem::create()->withText([
        RichText::createText("My link: "),
        RichText::createText("https://example.com/my-link")
            ->withUrl("https://example.com/my-link"),
    ]));
    
    opened by NFarrington 1
  • Use `never` on `BlockInterface::changeChildren()`

    Use `never` on `BlockInterface::changeChildren()`

    With the new never return type, the method BlockInterface::changeChildren() could optionally be marked as a never returning method, due to blocks that do no accept children.

    public function changeChildren(array $children): self|never
    
    enhancement 
    opened by mariosimao 1
Releases(v1.0.0)
  • v1.0.0(Nov 7, 2022)

    Added

    • Add database description (#125)
    • Add support to toggleable headings (#126)
    • Add caption to Code block (#127)
    • Add support to Status property (#132)
    • Icon value object instead of File|Emoji

    Changed

    • Unify constructor method names (#131)
    • Require PHP 8.1
    • Enums instead of constants for everything. Example: collor, block type, ...
    • Readonly public properties and removal of getters
    • Many method signatures were changed
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0-beta.2(Nov 2, 2022)

    Added

    • Add database description (#125)
    • Add support to toggleable headings (#126)
    • Add caption to Code block (#127)
    • Add support to Status property (#132)

    Changed

    • Unify constructor method names (#131)

    Documentation

    • Express psr/http-client dependency on documentation (#128)
    • Document blocks (#129)
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0-beta.1(Sep 26, 2022)

    Added

    • Icon value object instead of File|Emoji

    Changed

    • Require PHP 8.1
    • Enums instead of constants for everything. Example: collor, block type, ...
    • Readonly public properties and removal of getters
    • Many method signatures were changed

    Full Changelog: https://github.com/mariosimao/notion-sdk-php/compare/v0.6.2...v1.0.0-beta.1

    Source code(tar.gz)
    Source code(zip)
  • v0.6.2(Aug 19, 2022)

    Fixed

    • Missing Files page property (#105)

    Documentation

    • How to add and update page properties (#104)
    • How to get page content (#106)

    Full Changelog: https://github.com/mariosimao/notion-sdk-php/compare/v0.6.1...v0.6.2

    Source code(tar.gz)
    Source code(zip)
  • v0.6.1(Aug 5, 2022)

    Added

    • Add URL support to RichText objects (#89)

    Fixed

    • Wrong object to array conversion

    Full Changelog: https://github.com/mariosimao/notion-sdk-php/compare/v0.6.0...v0.6.1

    Source code(tar.gz)
    Source code(zip)
  • v0.6.0(Jul 5, 2022)

  • v0.5.2(Jun 22, 2022)

  • v0.5.1(Jun 2, 2022)

  • v0.5.0(May 13, 2022)

  • v0.4.0(Mar 25, 2022)

    Added

    • How to documentation for pages
    • Find block (#58)
    • Update block (#59)
    • Append blocks (#60)
    • Delete block (#61)

    Changed

    • Notion version to 2022-02-22 (#69)
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Dec 4, 2021)

    Added

    • Find block children
    • Find block children recursively
    • Link preview block
    • Column and column list blocks

    Changed

    • Blocks withChildren() methods renamed to changeChildren()
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Nov 20, 2021)

    Added

    • Breadcrumb block
    • Support discovery of more PSR clients with php-http/discovery

    Changed

    • Clients require implementations of RequestFactoryInterface
    • Rename Notion\Client::createWithPsrClient() to createWithPsrImplementations()
    • Rename Notion\Client to Notion\Notion
    • Rename Notion\Databases\Database::withTitle() to withAdvancedTitle()
    • Use list<RichText> instead of ...RichText on
      • Bookmark::withCaption()
      • BulletedListItem::withText()
      • Callout::withText()
      • Code::withText()
      • Heading1::withText()
      • Heading2::withText()
      • Heading3::withText()
      • NumberedListItem::withText()
      • Paragraph::withText()
      • Quote::withText()
      • ToDo::withText()
      • Toggle::withText()
      • Database::withAdvancedTitle()
      • Title::withRichTexts()
      • RichTextProperty::withText()
    • Use list<BlockInterface> instead of ...BlockInterface on
      • BulletedListItem::withChildren()
      • Callout::withChildren()
      • NumberedListItem::withChildren()
      • Paragraph::withChildren()
      • Quote::withChildren()
      • ToDo::withChildren()
      • Toggle::withChildren()
      • Notion\Pages\Client::create()
    • Use list<SelectOption> instead of ...SelectOption on
      • Select::withOptions()
      • MultiSelect::withOptions()
    • Use list<non-empty-string> instead of ...string on
      • MultiSelect::fromIds() and MultiSelect::fromNames()
      • Relation::create() and Relation::withRelations()
    • Use list<User> instead of ...User on
      • People::create() and People::withPeople()
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Nov 3, 2021)

    First release of notion-sdk-php ! 🎉

    Support to pages, databases and users API.

    Blocks:

    • bookmark
    • bulleted list item
    • callout
    • child database
    • child page
    • code
    • divider
    • embed
    • equation
    • file
    • heading 1
    • heading 2
    • heading 3
    • image
    • numbered list item
    • paragraph
    • PDF
    • quote
    • table of contents
    • to do
    • toggle
    • video

    Database and Page properties:

    • checkbox
    • created by
    • created time
    • date
    • email
    • files
    • formula
    • last edited by
    • last edited time
    • multi select
    • number
    • people
    • phone number
    • rich text
    • select
    • title
    • URL
    Source code(tar.gz)
    Source code(zip)
Owner
Mario Simão
Mario Simão
Notion PHP SDK

Notion PHP SDK This is an unofficial PHP SDK for the new public Notion API. It's work in progress as we didn't get the change to be included to the pr

Codecycler 43 Nov 29, 2022
The SDK written in PHP for Close partner developers.

Close SDK for PHP The Close SDK for PHP makes it easy for developers to communicate with The Close App in their PHP code. Get started really fast by i

Close Dev Team 3 Jun 23, 2022
Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs

Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs. It helps to access the API in an object-oriented way.

Thuong Le 77 Dec 19, 2022
Zoho CRM API SDK is a wrapper to Zoho CRM APIs. By using this sdk, user can build the application with ease

Archival Notice: This SDK is archived. You can continue to use it, but no new features or support requests will be accepted. For the new version, refe

null 81 Nov 4, 2022
This bundle provides tools to build a complete GraphQL server in your Symfony App.

OverblogGraphQLBundle This Symfony bundle provides integration of GraphQL using webonyx/graphql-php and GraphQL Relay. It also supports: batching with

Webedia - Overblog 720 Dec 25, 2022
Tukio is a complete and robust implementation of the PSR-14 Event Dispatcher specification

Tukio is a complete and robust implementation of the PSR-14 Event Dispatcher specification. It supports normal and debug Event Dispatchers, both runtime and compiled Providers, complex ordering of Listeners, and attribute-based registration on PHP 8.

Larry Garfield 70 Dec 19, 2022
This package makes it easy for developers to access WhatsApp Cloud API service in their PHP code.

The first PHP API to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

NETFLIE 135 Dec 29, 2022
Best resources restful api for developers

Best resources restful api for developers (with JSON:API standar specification design).

Noval 2 Jan 18, 2022
Best resources restful api for developers (with JSON:API standar specification design)

List API Best resources restful api for developers (with JSON:API standar specification design). API Resource Endpoint Name Resource Description Al Qu

Noval 2 Jan 18, 2022
The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructure and leverage the power of 1Password Secrets Automation

1Password Connect PHP SDK The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructu

Michelangelo van Dam 12 Dec 26, 2022
Facebook SDK for PHP (v6) - allows you to access the Facebook Platform from your PHP app

Facebook SDK for PHP (v6) This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app. Installa

null 0 Aug 10, 2022
Unofficial Firebase Admin SDK for PHP

Firebase Admin PHP SDK Table of Contents Overview Installation Documentation Support License Overview Firebase provides the tools and infrastructure y

kreait 1.9k Jan 3, 2023
爱发电非官方简易 PHP SDK

afdian-php-sdk 爱发电非官方简易 PHP SDK by Akkariin 这是一个简单的 SDK,可以用于查询爱发电的订单和赞助者信息 Installation 将项目 clone 到本地即可 git clone https://github.com/ZeroDream-CN/afdi

ZeroDream-CN 17 Nov 7, 2022
AWS Cognito package using the AWS SDK for PHP/Laravel

Laravel Package to manage Web and API authentication with AWS Cognito AWS Cognito package using the AWS SDK for PHP This package provides a simple way

EllaiSys 74 Nov 15, 2022
PHP SDK to interact with the Casper Network nodes via RPC

casper-php-sdk PHP SDK to interact with Casper Network nodes via RPC Install composer require make-software/casper-php-sdk Examples RPC Client: $node

MAKE Technology LLC 7 May 8, 2022
A Laravel 5+ (and 4) service provider for the AWS SDK for PHP

AWS Service Provider for Laravel 5/6/7/8 This is a simple Laravel service provider for making it easy to include the official AWS SDK for PHP in your

Amazon Web Services 1.5k Dec 28, 2022
SDK of the LINE Login API for PHP

LINE Login for PHP SDK of the LINE Login API for PHP Documentation See the official API documentation for more information. Installation Use the packa

null 4 Sep 15, 2022
PHP SDK - Flexie CRM fiskalizimi solution

PHP SDK - Flexie CRM fiskalizimi solution Fiskalizimi PHP SDK allows you to talk and generate your e-invoices programmatically from your own solution

Flexie CRM 3 Dec 30, 2021
PHP Digital Green Certificate SDK

Digital Green Certificate SDK PHP Indice Contesto Installazione Uso Licenza Dettaglio licenza Contesto Attenzione, questo repository è derivato dalle

null 13 Jun 20, 2022