jamalex / notion-py

Unofficial Python API client for Notion.so
MIT License
4.28k stars 475 forks source link

get_collection_view returning None #204

Open diallobakary4 opened 3 years ago

diallobakary4 commented 3 years ago

The code below works well in modifying a page. But it keeps on returning None when I try to access a database.

from notion.client import NotionClient
client = NotionClient(token_v2=token)
# Replace this URL with the URL of the page you want to edit
page = client.get_block("https://www.notion.so/xxx")
print("The old title is:", page.title)
# Note: You can use Markdown! We convert on-the-fly to Notion's internal formatted text data structure.
page.title = "The title has now changed, and has *live-* in the !"

task_database = "https://www.notion.so/xxx?v=xxx"
cv = client.get_collection_view(task_database)
print(cv)
AlexMikhalev commented 3 years ago

I think it's not only collections, get() on page returns none:

page
Out[22]: <PageBlock (id='removed', title='Academic Web Page from Notion using Hugo')>
print(page.get())
None

Successfully created page returns None when get() called.

WardBenjamin commented 3 years ago

I am not having this problem with get_collection_view

AlexMikhalev commented 3 years ago

@WardBenjamin interesting, what is your notion py version and how do you use it?

WardBenjamin commented 3 years ago

@AlexMikhalev looks like 0.0.25, latest on PyPI. Both client.get_block(url) and client.get_collection_view(url) are working for me, with URLs in the format of https://www.notion.so/xxxx?v=yyyy

Except for embedded images, all of the read API's that I've tried so far seem to be working for me. Something about the security policy on the image requests is also broken, as are quite a few other things about the library (most of the write/sync APIs, particularly anything that calls submitTransaction since Notion seems to only use saveTransaction in the web version). It seems like waiting until the official release might be the only real option if you want to do anything more than reading text.

AlexMikhalev commented 3 years ago

Thank you, I hacked my way around lack of raw response, I will be waiting for next release.

bisaacs42 commented 3 years ago

FYI for those interested, I had this exact issue and resolved it...by pip install notion

rather than pip install notion-py

Not exactly a fix, but hopefully a workaround for those who were scratching their heads like me

ag0n1k commented 3 years ago

The same for me. My investigations are:

# the collection id in notion-py is 'raw' format
LINK = "https://www.notion.so/some_org/70b752520eec4ab0a58d20ec85553228?v=f11274fabdeb41bfb3383f24a5e2672f"
client = NotionClient(token_v2=TOKEN_V2)
cv = client.get_collection_view(DB_LINK)
# the collection id is 70b752520eec4ab0a58d20ec85553228
# but in browser the collection id is 0b3de74d-630c-489e-bf0d-059f23e41e06

Installing notion not notion-py helps, thanks @bisaacsdfs.

odeckmyn commented 3 years ago

had to make the Notion page public for this to work for me