Skip to content

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

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

Open
paperboi opened this issue Sep 24, 2020 · 7 comments · May be fixed by #266
Open

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

paperboi opened this issue Sep 24, 2020 · 7 comments · May be fixed by #266
Labels
enhancement New feature or request help wanted Contributions and suggestions welcome

Comments

@paperboi
Copy link

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.

@TheSpeedM
Copy link

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

@paperboi
Copy link
Author

paperboi commented Oct 7, 2020

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.

@c-schaer
Copy link
Contributor

c-schaer commented Nov 7, 2020

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

@TheSpeedM
Copy link

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.

@c-schaer
Copy link
Contributor

c-schaer commented Nov 8, 2020

Dang, that is unfortunate. Thanks for the heads up

@jamalex
Copy link
Owner

jamalex commented Nov 22, 2020

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 jamalex added enhancement New feature or request help wanted Contributions and suggestions welcome labels Nov 22, 2020
@ITAYC0HEN ITAYC0HEN linked a pull request Jan 30, 2021 that will close this issue
@tortoisecatfish
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Contributions and suggestions welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants