Coder Social home page Coder Social logo

Comments (2)

mariosimao avatar mariosimao commented on August 22, 2024 1

Sorry for the delay, I have been quite busy lately.

First of all, it is necessary to understand that database rows on Notion are essentially pages where the parent is the database.

Add a row to a database

<?php

require "vendor/autoload.php";

$token = "your_secret_here";
$notion = \Notion\Notion::create($token);

$databaseId = "your_database_id_here";
$parent = \Notion\Pages\PageParent::database($databaseId);

$title    = \Notion\Pages\Properties\Title::create("Superbad");
$release  = \Notion\Pages\Properties\Date::create(new DateTimeImmutable("2007-10-19"));
$category = \Notion\Pages\Properties\Select::fromName("Comedy")
    ->withColor(\Notion\Pages\Properties\Option::COLOR_BROWN);

$page = \Notion\Pages\Page::create($parent)
    ->withAddedProperty("Title", $title)
    ->withAddedProperty("Release date", $release)
    ->withAddedProperty("Category", $category);

$notion->pages()->create($page);

Before:
image

After:
image

Change the value of a property

<?php

require "vendor/autoload.php";

$token = "your_secret_here";
$notion = \Notion\Notion::create($token);

$pageId = "your_page_id_here";
$page = $notion->pages()->find($pageId);

$updatedRelease = \Notion\Pages\Properties\Date::create(new DateTimeImmutable("2008-11-04"));
$updatedPage = $page->withAddedProperty("Release date", $updatedRelease);

$notion->pages()->update($updatedPage);

Before:
image

After:
image

Since there are no examples of adding rows to a database and updating properties, I will leave this issue open.

Thanks for your feedback!

from notion-sdk-php.

mariosimao avatar mariosimao commented on August 22, 2024

Documentation is available on v0.6.2

from notion-sdk-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.