notion-py
notion-py copied to clipboard
Is it possible to create a new row from a page template in a database?
I would like to automate an action where a row/page is created everyday. The contents of the page should be retreived from a template stored in the db. Wrote a makeshift solution using copy but it's too slow and inefficient for what I'm looking for. Is there a script or function in notion.py that can let me create a page using a template? Thanks.
I wrote a copy function for issue #125, does this solution suit your needs?
I wrote a copy function for issue #125, does this solution suit your needs?
Hey, your solution works, except that it'd would be slow for long templates (since copy-pasting each element takes some considerable time) and for styling related issues (Text/Block elements reverting to default colors and font styles). I was hoping to figure a way to import a page template directly into my page, just like what the New>Template button in a DB would do.
Did you ever come up with a solution or workaround? I have a similar use case.
Sadly, New > Template is handled by the JavaScript on the page, not by the back-end (same for duplicating blocks). The only POST-request that is send to the server are the properties of the new page/block.
Dang, that is unfortunate. Thanks for the heads up
It looks as if "Duplicate", in any case, happens on the server side. If anyone wants to give this a shot, check out calls to the following API endpoints:
- /api/v3/enqueueTask
- /api/v3/getTasks
The API looks fairly straightforward; the main complication is that it's async, so you either need to make the method (e.g. NotionClient.duplicate_block
) block and loop while it checks getTasks
, or make it return the task ID (or an object-oriented wrapper with a get_status
method).
It looks as if "Duplicate", in any case, happens on the server side. If anyone wants to give this a shot, check out calls to the following API endpoints:
- /api/v3/enqueueTask
- /api/v3/getTasks
The API looks fairly straightforward; the main complication is that it's async, so you either need to make the method (e.g.
NotionClient.duplicate_block
) block and loop while it checksgetTasks
, or make it return the task ID (or an object-oriented wrapper with aget_status
method).
I looked into this a bit and wasn't able to get it running mainly because V3 doesn't take Bearer for authorization like V1 does. Any idea what it does take? token_v2 or something for v3? I will inspect its communications. I'm writing it in curl btw so far I'm able to use append blocks API that they posted for their official API but since a page is not seen as a block (it is returned as type:unsupported because it only sees things like toggle as a block) I wasn't able to append a page inside a template(page/row) to a newly created page/row.