notion-py icon indicating copy to clipboard operation
notion-py copied to clipboard

Is it possible to create a new row from a page template in a database?

Open paperboi opened this issue 3 years ago • 7 comments

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.

paperboi avatar Sep 24 '20 02:09 paperboi

I wrote a copy function for issue #125, does this solution suit your needs?

TheSpeedM avatar Sep 30 '20 14:09 TheSpeedM

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.

paperboi avatar Oct 07 '20 13:10 paperboi

Did you ever come up with a solution or workaround? I have a similar use case.

c-schaer avatar Nov 07 '20 17:11 c-schaer

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.

TheSpeedM avatar Nov 08 '20 14:11 TheSpeedM

Dang, that is unfortunate. Thanks for the heads up

c-schaer avatar Nov 08 '20 19:11 c-schaer

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).

jamalex avatar Nov 22 '20 06:11 jamalex

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).

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.

tortoisecatfish avatar May 23 '21 09:05 tortoisecatfish