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

Get all pages #43

Closed
mvaldes14 opened this issue Aug 6, 2019 · 3 comments
Closed

Get all pages #43

mvaldes14 opened this issue Aug 6, 2019 · 3 comments

Comments

@mvaldes14
Copy link

Is there a way to pass a token and get all pages for a user?
most of the methods require you to pass a url to get the ID of the blocks and then interact with them but was wondering if there could be a higher function to get everything in a user workspace.

been trying to understand whats the real endpoint the api hits and from what i can see its something like notion.so/api/v3 but then what else is passed down to it? could that be something on the wiki page for people to test out things?

@iansinnott
Copy link

I think there must be a better way to do this, but the following code works for me. The key starting point is client.current_space.pages:

def get_all_notion_pages():
    def get_children(block):
        result = []
        for child in block.children:
            if child.type == 'page':
                result.append(child)
                result += get_children(child)
        return result

    pages = []

    for page_id in client.current_space.pages:
        block = client.get_block(page_id)
        if block.type == 'page':
            pages.append(block)
            pages += get_children(block)

    return pages

@jamalex
Copy link
Owner

jamalex commented Jan 3, 2020

Thanks for the issue!

Sort of a duplicate of #50 -- and has been addressed in #87, which will be in an upcoming release.

@jamalex jamalex closed this as completed Jan 3, 2020
@mvaldes14
Copy link
Author

much appreciated!

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

3 participants