5am-code / laravel-notion-api Goto Github PK
View Code? Open in Web Editor NEWEffortless Notion integrations with Laravel
Home Page: https://notionforlaravel.com
License: MIT License
Effortless Notion integrations with Laravel
Home Page: https://notionforlaravel.com
License: MIT License
Hello,
I want to fetch a content of page (blocks), to create a blog with articles.
My notion structure :
I'd like to be able to foreach every page in this database and browse the page content.
I was inspired by the code given here:
However, while trying to debug the code, I noticed that it was blocking here:
mapTypeToClass() -> fromResponse() from the Block.php class
Giving me the following error:
Undefined array key "text"
Do you have any idea where this might be coming from? If you need more information, don't hesitate to ask.
I'd like to use the compound filters (currently a TODO comment) when querying a database. Specifically, I would like to use an "and" filter to add two filters at the same time.
Really just opening the issue to give me a place to track it whenever it gets implemented - love this package thanks for all your excellent work on it.
Hello,
I want to sort my Search with Created Time and not the Last Edited Time.
In the Search class, I've created another method :
/**
* @param string $direction
* @return $this
*/
public function sortByCreatedTime(string $direction = 'ascending'): Search
{
$this->sort = Sorting::timestampSort('created_time', $direction);
return $this;
}
But I receive this error :
Bad Request: (validation_error) (body failed validation: body.sort.timestamp should be
"last_edited_time"
, instead was"created_time"
.)
Describe the bug
In NotionException::fromResponse(), array_key_exists
throws an exception when $responseBody is null, in the statement if (array_key_exists("code", $responseBody))
.
To Reproduce
This cropped up on our production site but not sure how to reproduce it. It happened during a call to Notion::pages()->update($page);
, and when the call fails inside Endpoint::patch()
and an attempt is made to throw a NotionException.
Laravel 9. PHP 8.
Expected behavior
$responseBody
is check to make sure it isn't null before calling array_keys with it.
Exceptions
[2023-04-20 09:40:45] production.ERROR: array_key_exists(): Argument #2 ($array) must be of type array, null given {"userId":1820,"exception":"[object] (TypeError(code: 0): array_key_exists(): Argument #2 ($array) must be of type array, null given at /home/forge/notioninvoice.com/vendor/fiveam-code/laravel-notion-api/src/Exceptions/NotionException.php:39)
[stacktrace]
#0 /home/forge/notioninvoice.com/vendor/fiveam-code/laravel-notion-api/src/Exceptions/NotionException.php(39): array_key_exists()
#1 /home/forge/notioninvoice.com/vendor/fiveam-code/laravel-notion-api/src/Endpoints/Endpoint.php(131): FiveamCode\\LaravelNotionApi\\Exceptions\\NotionException::fromResponse()
#2 /home/forge/notioninvoice.com/vendor/fiveam-code/laravel-notion-api/src/Endpoints/Pages.php(107): FiveamCode\\LaravelNotionApi\\Endpoints\\Endpoint->patch()
#3 /home/forge/notioninvoice.com/app/Http/Livewire/Invoice/NewInvoice.php(608): FiveamCode\\LaravelNotionApi\\Endpoints\\Pages->update()
#4 /home/forge/notioninvoice.com/app/Http/Livewire/Invoice/NewInvoice.php(479): App\\Http\\Livewire\\Invoice\\NewInvoice->updateInvoiceInNotion()
#5 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\\Http\\Livewire\\Invoice\\NewInvoice->createAndSend()
#6 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#7 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#8 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#9 /home/forge/notioninvoice.com/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php(149): Illuminate\\Container\\BoundMethod::call()
#10 /home/forge/notioninvoice.com/vendor/livewire/livewire/src/HydrationMiddleware/PerformActionCalls.php(35): Livewire\\Component->callMethod()
#11 /home/forge/notioninvoice.com/vendor/livewire/livewire/src/LifecycleManager.php(82): Livewire\\HydrationMiddleware\\PerformActionCalls::hydrate()
#12 /home/forge/notioninvoice.com/vendor/livewire/livewire/src/Connection/ConnectionHandler.php(12): Livewire\\LifecycleManager->hydrate()
#13 /home/forge/notioninvoice.com/vendor/livewire/livewire/src/Controllers/HttpConnectionHandler.php(20): Livewire\\Connection\\ConnectionHandler->handle()
#14 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(48): Livewire\\Controllers\\HttpConnectionHandler->__invoke()
#15 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Routing/Route.php(261): Illuminate\\Routing\\ControllerDispatcher->dispatch()
#16 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Routing/Route.php(204): Illuminate\\Routing\\Route->runController()
#17 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php(695): Illuminate\\Routing\\Route->run()
#18 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#19 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#20 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle()
#21 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#22 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle()
#23 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#24 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle()
#25 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Session/Middleware/AuthenticateSession.php(58): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#26 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Session\\Middleware\\AuthenticateSession->handle()
#27 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#28 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest()
#29 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Session\\Middleware\\StartSession->handle()
#30 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#31 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle()
#32 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#33 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle()
#34 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#35 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php(697): Illuminate\\Pipeline\\Pipeline->then()
#36 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php(672): Illuminate\\Routing\\Router->runRouteWithinStack()
#37 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php(636): Illuminate\\Routing\\Router->runRoute()
#38 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php(625): Illuminate\\Routing\\Router->dispatchToRoute()
#39 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(166): Illuminate\\Routing\\Router->dispatch()
#40 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#41 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#42 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle()
#43 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(36): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#44 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle()
#45 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#46 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle()
#47 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#48 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#49 /home/forge/notioninvoice.com/vendor/fruitcake/laravel-cors/src/HandleCors.php(38): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#50 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fruitcake\\Cors\\HandleCors->handle()
#51 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#52 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\\Http\\Middleware\\TrustProxies->handle()
#53 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#54 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(141): Illuminate\\Pipeline\\Pipeline->then()
#55 /home/forge/notioninvoice.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#56 /home/forge/notioninvoice.com/public/index.php(52): Illuminate\\Foundation\\Http\\Kernel->handle()
#57 {main}
Describe the bug
When trying to update a page, it fails with a client exception due to the incorrect JSON format sent to Notion.
To Reproduce
The following code:
$page = NotionFacade::pages()->find($id);
$page->set('Name', \FiveamCode\LaravelNotionApi\Entities\Properties\Title::value('Test here'));
NotionFacade::pages()->update($page);
Expected behaviour
The code should save the page's properties.
Exceptions
1) Tests\Feature\NotionTest::test_example2
FiveamCode\LaravelNotionApi\Exceptions\NotionException: Bad Request: (validation_error) (body failed validation. Fix one:
body.properties.Name.id should be defined, instead was `undefined`.
body.properties.Name.headers should be not present, instead was `undefined`.
body.properties.Name.statusCode should be not present, instead was `400`.
body.properties.Name.body should be not present, instead was `{"object":"error","status":400,"code":"validation_error...`.
body.properties.Name.start should be defined, instead was `undefined`.)
/Users/peterfox/Code/Experiments/sushi-and-notion/vendor/laravel/framework/src/Illuminate/Http/Client/Response.php:272
/Users/peterfox/Code/Experiments/sushi-and-notion/vendor/fiveam-code/laravel-notion-api/src/Exceptions/NotionException.php:61
/Users/peterfox/Code/Experiments/sushi-and-notion/vendor/fiveam-code/laravel-notion-api/src/Endpoints/Endpoint.php:138
/Users/peterfox/Code/Experiments/sushi-and-notion/vendor/fiveam-code/laravel-notion-api/src/Endpoints/Pages.php:105
/Users/peterfox/Code/Experiments/sushi-and-notion/app/Models/Item.php:61
/Users/peterfox/Code/Experiments/sushi-and-notion/tests/Feature/NotionTest.php:27
/Users/peterfox/Code/Experiments/sushi-and-notion/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:174
Caused by
Illuminate\Http\Client\RequestException: HTTP request returned status code 400:
{"object":"error","status":400,"code":"validation_error","message":"body failed validation. Fix one:\nbody.properties.Na (truncated...)
/Users/peterfox/Code/Experiments/sushi-and-notion/vendor/laravel/framework/src/Illuminate/Http/Client/Response.php:272
/Users/peterfox/Code/Experiments/sushi-and-notion/vendor/fiveam-code/laravel-notion-api/src/Exceptions/NotionException.php:61
/Users/peterfox/Code/Experiments/sushi-and-notion/vendor/fiveam-code/laravel-notion-api/src/Endpoints/Endpoint.php:138
/Users/peterfox/Code/Experiments/sushi-and-notion/vendor/fiveam-code/laravel-notion-api/src/Endpoints/Pages.php:105
/Users/peterfox/Code/Experiments/sushi-and-notion/app/Models/Item.php:61
/Users/peterfox/Code/Experiments/sushi-and-notion/tests/Feature/NotionTest.php:27
/Users/peterfox/Code/Experiments/sushi-and-notion/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:174
Additional context
I've played around with the properties, and the rawContent structure needs to be corrected. When using the following classes, the page is updated as expected.
<?php
namespace App\Notion;
class Title extends \FiveamCode\LaravelNotionApi\Entities\Properties\Title
{
public static function value($text): \FiveamCode\LaravelNotionApi\Entities\Properties\Title
{
$titleProperty = parent::value($text);
$titleProperty->rawContent = [
0 => [
'text' => [
'content' => $titleProperty->getRichText()->getPlainText(),
],
],
];
return $titleProperty;
}
}
<?php
namespace App\Notion;
class Url extends \FiveamCode\LaravelNotionApi\Entities\Properties\Url
{
public static function value(string $url): \FiveamCode\LaravelNotionApi\Entities\Properties\Url
{
$urlProperty = parent::value($url);
$urlProperty->rawContent = $url;
return $urlProperty;
}
}
My guess is Notion has changed the format of the API and the package doesn't take account of that when it comes to updating.
Describe the bug
In an api-update, Notion introduced a new format for the property last_edited_time.
To Reproduce
Querying a database with a property, which has "last_edited_time" as type.
Expected behavior
Collection/Json of pages based on the sent database-query, which includes the values for the property that has "last_edited_time" as type.
Exceptions
-
Additional context
-
Using the sample code from the documentation, the page title does not appear. The page is created normally, but the title seems to be ignored. The documentation states that creating a child page does not allow properties, but in the example, it seems that a title is being set.
$parentID = '';
$page = new Page();
$page->set('Name', Title::value('I was created from Laravel'));
$newPage = $this->notion->pages()->createInPage($parentID, $page);
I was expecting to create a new page with a predefined title.
Is your feature request related to a problem? Please describe.
At the moment, when retrieving a page using the pages() endpoint, the result returns a maximum of 25 references for each relation property.
Describe the solution you'd like
To more than 25 references inside a relation property, Notion requires us to use the "Retrieve a page property item" endpoint along with paging, documented here: https://developers.notion.com/reference/retrieve-a-page-property
This issue and solution are also described in this article: https://notionmastery.com/pushing-notion-to-the-limits/#prop-refs-api
I don't know if this endpoint is already in this package (I can't find any documentation on it), so if it isn't, would it be possible to add it?
Thanks!
Is your feature request related to a problem? Please describe.
For my needs, I don't know what the notion token will be. It will be included in a request passed to my app by the user that I will pass along to Notion's API. Having the only means of authentication as a .env variable makes establishing that workflow difficult.
Describe the solution you'd like
If no .env variable exists, the class constructor should throw an exception stating that a Notion token needs to be defined via the NOTION_API_TOKEN
.env variable or passed to the constructor. The constructor can look something like:
protected string $notionApiToken;
public function __construct(string $notionApiToken = null) {
$configuredNotionApiToken = config('laravel-notion-api.token');
if(empty($configuredNotionApiToken) {
if(empty($notionApiToken)) {
throw new \Exception("Notion API token must be defined either in 'NOTION_API_TOKEN' .env variable or passed to constructor.")
}
$this->notionApiToken = $notionApiToken;
} else {
$this->notionApiToken = $configuredNotionApiToken;
}
}
Describe the bug
The current documentation is wrong
To Reproduce
PHP v8.3.2
Laravel v10
use \Notion;
Notion::databases()->find("8284f3ff77e24d4a939d19459e4d6bdc");
Expected behavior
Works without any issue
Additional context
First thing first if you use use Notion;
you will get this error "Undefined class Notion"
Instead, you should use use FiveamCode\LaravelNotionApi\Notion;
Second Notion::databases()->find($databaseId);
you will get this error "Non-static method 'databases' should not be called statically "
The documentation is misleading and incomplete.
Search-Endpoint while searching using a cursor is broken.
Here it is correct:
Bug: generates an empty array/object:
Error message
Bad Request: (validation_error) (body failed validation: body.start_cursor should be a string or `undefined`, instead was `{}`.)
Hi. Thanks for this great package!
Describe the bug
I'm trying to create a page in a database, and following the example here: https://5amco.de/docs/0.5.0/examples/update_create/create_page
Basically this didn't work because the method createInDatabase
doesn't exist in the Notion class: Notion::createInDatabase($databaseId, $page);
To Reproduce
Try to run Notion::createInDatabase($databaseId, $page);
Laravel: 8.56
Expected behavior
A page is successfully created in Notion.
Exceptions
None.
Additional context
I did notice that the Pages
class does have the createInDatabase
, I tried the following code, but that returned a "Bad Request" error.
use FiveamCode\LaravelNotionApi\Notion;
use FiveamCode\LaravelNotionApi\Entities\Page;
$notion = new Notion($token);
$page = new Page();
$page->setTitle("Title", "Date Prop");
$notion->pages()->createInDatabase($dbId, $page);
Describe the bug
When a NotionException is thrown, the code is always 0
.
To Reproduce
No reproduction needed. See code:
laravel-notion-api/src/Exceptions/NotionException.php
Lines 47 to 51 in 4f75db6
Expected behavior
The exception should contain the HTTP Status code.
Exceptions
.
Additional context
.
See my PR
#88
Hey hey,
hope this is not a newbie issue. First of all thanks for the amazing job. I'm having some issues with pagination.
I'm using the package within laravel. When querying a database it seems that the returned results are a Laravel Collection and the method getNextCursor doesn't exist. here's the error I'm getting:
BadMethodCallException
Method Illuminate\Support\Collection::getNextCursor does not exist.
at vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php:113
109▕ */
110▕ public function __call($method, $parameters)
111▕ {
112▕ if (! static::hasMacro($method)) {
➜ 113▕ throw new BadMethodCallException(sprintf(
114▕ 'Method %s::%s does not exist.', static::class, $method
115▕ ));
116▕ }
117▕
and my sample code:
if(!$offset)
{
$tasks=$notion->database($databaseId)
->sortBy($sortings)
->limit(5)
->query()
->asCollection();
} else {
$tasks=$notion->database($databaseId)
->sortBy($sortings)
->offset($offset)
->limit(5)
->query()
->asCollection();
}
$offset= $tasks->getNextCursor();
Any help would be hugely appreciated :)
Describe the bug
The union type float|int
in the function definition of Filter::numberFilter() is flagged as a syntax error, when using PHP 7.4.
Union types are only valid in PHP8.0 and above, but PHP 7.4 is being supported in composer.json.
To Reproduce
Call Filter::numberFilter() while using PHP 7.4.
Expected behavior
There should not be a syntax error.
Exceptions
This works fine in PHP8.0. So maybe remove all use of union types or make PHP8.0 the minimum requirement?
Additional context
None.
Is your feature request related to a problem? Please describe.
At the moment when a Date property is added to a Page, it's automatically set with date and time, even if time is actually not needed.
Describe the solution you'd like
It would be awesome if we could choose wether to display time or not! Because displaying time in Notion when not needed is a bit "polluting".
Describe alternatives you've considered
In the meantime I make sure I set my Datetime with 0 in hours, minutes and seconds.
When there is an exception, I need to know if it's related to rate limits, and if it is, I then need to get the 'Retry-After' header to determine my backoff time.
How can I have access to the response header?
Thanks.
I'm trying to retrieve a simple list of pages in a database. In Notion, I have manually dragged and re-ordered these to be in a specific order.
When I retrieve them simply as a collection...
Notion::database($databaseId)->query()->asCollection();
... and loop through, they are not in the same order as in Notion.
Yes I know I can specify explicit ordering, but I don't have any field/property that I can order on. My goal is to let the user manually drag to order items, and display them in that same order in my app.
Is this possible?
I can see in the Entities\Properties - Files is listed as property, however, setFiles() function is not present in the Page.php..
Is this something that can be added? Thank you :) @mechelon
Describe the bug
When fetching all users from a workspace, integrations/bots are incorrectly shown as "user" instead of "bot". The raw response appears to be correct, but using ->asCollection() sets them as a user.
To Reproduce
Laravel 10, PHP 8.1
$notionUsers = \Notion::users()->all()->asCollection();
foreach ($notionUsers as $user) {
dump($user->getObjectType());
}
Expected behavior
Users should be set as "user", and bots should be set as "bot", as it is in the raw response.
Hey, I have some Notion records (pages) where they have properties but also have this text inside the page:
Reading the Notion API documentation I figured out this is a rich text https://developers.notion.com/reference/rich-text however I am unable to find how to use it..
Do you know if this is supported by the Notion API or not? Because I saw in your code you already have created a RichText property but couldn't find how to call that function.. Thanks!
Describe the bug
When using the Notion::database() method to retrieve pages in a database, a HandlingException is thrown if it encounters a Rollup that refers to a Select, and that Select is empty.
The exception is thrown inside FiveamCode\LaravelNotionApi\Entities\Properties\Select::fillFromRaw(). Exception message:
"The property-type is select, however the raw data-structure does not reprecent this type. Please check the raw response-data."
To Reproduce
Laravel 8.60, OS MacOS 11.6 (Bug Sur), PHP 8.0.14.
Now use the following code to read the DB2 database:
$notion = new Notion(secret_key);
$results = $notion->database(id_for_DB2)->query();
Expected behavior
All rows from DB2 should be returned in $results. Instead, HandlingException is thrown with the message
"The property-type is select, however the raw data-structure does not reprecent this type. Please check the raw response-data."
I am trying to use this library without laravel, but seems its doesn't suppose to work.
php
use FiveamCode\LaravelNotionApi\Notion;
$notion = new Notion('');
Error:
Fatal error: Uncaught RuntimeException: A facade root has not been set. in /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/vendor/illuminate/support/Facades/Facade.php:335 Stack trace: #0 /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/vendor/fiveam-code/laravel-notion-api/src/Notion.php(72): Illuminate\Support\Facades\Facade::__callStatic('withHeaders', Array) #1 /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/vendor/fiveam-code/laravel-notion-api/src/Notion.php(62): FiveamCode\LaravelNotionApi\Notion->connect() #2 /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/plugin.php(29): FiveamCode\LaravelNotionApi\Notion->__construct('') #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/illuminate/support/Facades/Facade.php on line 335
any ideas how to fix this ?
Describe the bug
When I use Filter::rawFilter to query a Notion database on a status property type, a validation error is returned.
To Reproduce
Set the filter and send the query:
$filters = new Collection();
$filters->add(Filter::rawFilter("Status",
["status" => [Operators::EQUALS => "Ready"]]
));
$notion = new Notion($access_token)
$rows = $notion->database($id)
->filterBy($filters)
->sortBy($sortings)
->query()
->asCollection();
Expected behavior
A filtered results collection is returned.
Exceptions
Trace can be found here: https://flareapp.io/share/pPv1vqYm#F58
Additional context
Describe the bug
The operators 'contains' should be callable by the const CONTAINS, however there is a typo 'conain', which should be 'contain'
To Reproduce
-
Expected behavior
-
Exceptions
-
Additional context
-
Is your feature request related to a problem? Please describe.
Right now you can retrieve the content of a page (child blocks) with all the notion raw data, like annotations and so on. But In case you want to render it somewhere you will have manually go through all the blocks, apply the annotations and concatenate all blocks rendered output together.
Describe the solution you'd like
I've started to create a collection of renderer classes transforming the different blocks and sub-entities to markdown. Markdown as it's short and easy to store in a database or file and can be used in different languages and has no definitions of how it's rendered, with which tags, classes or could even be used in non-HTML renderers.
Describe alternatives you've considered
Markdown is probably not the best/most feature-complete option as Notion allows to colorize or underline text, both aren't possible with markdown. So HTML could be a better option - even if I would like to have the choice if HTML should be implemented. So a driver-based renderer and not forcing the user to use the one we picked.
Additional context
Here's for example the RichTextRenderer
which is one of the most common ones and would do the most work:
<?php
namespace App\Renderers;
use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText;
use Illuminate\Support\Str;
use Illuminate\Support\Stringable;
class RichTextRenderer extends Renderer
{
public function __construct(protected RichText $richText)
{
}
public function render(): ?string
{
return collect($this->richText->getRawResponse())
->map(static function (array $data): string {
return Str::of($data['plain_text'])
->when(
$data['annotations']['italic'],
fn (Stringable $s) => $s->prepend('_')->append('_')
)
->when(
$data['annotations']['bold'],
fn (Stringable $s) => $s->prepend('**')->append('**')
)
->when(
$data['annotations']['strikethrough'],
fn (Stringable $s) => $s->prepend('~')->append('~')
)
->when(
$data['annotations']['code'],
fn (Stringable $s) => $s->prepend('`')->append('`')
)
->when(
$data['type'] === 'mention' && $data['mention']['type'] === 'page',
fn (Stringable $s) => $s->prepend('@[')->append("]({$data['mention']['page']['id']})")
);
})
->implode('');
}
}
Is your feature request related to a problem? Please describe.
It would be super-nice to be able to make multiple requests at the same time.
https://laravel.com/docs/8.x/http-client#concurrent-requests
Describe the solution you'd like
Add more methods to Endpoint classes, for example: queryAsync
, findAsync
, etc. All of these methods can return Promise
, which users can wrap into Http::pool
.
Describe alternatives you've considered
Manually making requests without using this package? Doesn't feel too good but it's the way for now.
Additional context
Due to the fact that Notion doesn't have webhooks at the moment, I think there is a need to manually pool Notion API. It would work much faster if we can make multiple requests at once, even with 3 requests per second limit.
Hello,
I use Notion as a database to make the content of my site manageable.
To retrieve the content I use "Notion::search()", but I have to use this function for each editable content which makes the page take 15 seconds to load (about 200 contents).
Is it possible to fetch the whole database once and then go and get the content ?
If yes, how to proceed?
Thanks in advance
Describe the bug
When adding a Youtube Video to a newly created Notion page the block is correctly added with its caption, the origin link sends to the correct video in Youtube, but the youtube player is not rendered correctly:
To Reproduce
$newBlock = Video::create("https://www.youtube.com/watch?v=KLPZzf-wwlE",$video['title']);
$notion->block($notionPage->getId())->append($newBlock);
Bonus Quesion
Is there a way to create the page using a template? :)
Thank you so much for your hard work on this great library
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.