Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Page fails with validation error from Notion #168

Open
peterfox opened this issue Aug 19, 2023 · 0 comments
Open

Updating Page fails with validation error from Notion #168

peterfox opened this issue Aug 19, 2023 · 0 comments

Comments

@peterfox
Copy link

peterfox commented Aug 19, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant