notion-py: 400 error when getting collection view

Tracceback is below. Quick start instructions worked fine on a page, but when trying to pick up a database/collection I get the following. Any suggestions, and thanks!

File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/notion/client.py", line 98, in get_collection_view
    collection = self.get_block(block_id, force_refresh=force_refresh).collection
  File "/usr/local/lib/python3.7/site-packages/cached_property.py", line 35, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python3.7/site-packages/notion/block.py", line 618, in collection
    self._collection = self._client.get_collection(collection_id)
  File "/usr/local/lib/python3.7/site-packages/notion/client.py", line 70, in get_collection
    return Collection(self, collection_id) if coll else None
  File "/usr/local/lib/python3.7/site-packages/notion/collection.py", line 104, in __init__
    self._client.refresh_collection_rows(self.id)
  File "/usr/local/lib/python3.7/site-packages/notion/client.py", line 115, in refresh_collection_rows
    row_ids = self.search_pages_with_parent(collection_id)
  File "/usr/local/lib/python3.7/site-packages/notion/client.py", line 172, in search_pages_with_parent
    response = self.post("searchPagesWithParent", data).json()
  File "/usr/local/lib/python3.7/site-packages/notion/client.py", line 126, in post
    raise HTTPError(response.json().get("message", "There was an error (400) submitting the request."))
requests.exceptions.HTTPError: Invalid input.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (5 by maintainers)

Most upvoted comments

My version currently has a fix. I couldn’t find any example of “searchPagesWithParent” in my network logs while trying various things. In the javascript source I did find something like this: searchPagesWithParent({query:e,parentId:s.id,limit:20,spaceId:a.id}). So the only change needed was a spaceId, which you can get from client.current_space.id.

(If you view my commits, I also had a solution ready that avoided searchPagesWithParent calls entirely by replacing it with queryCollection calls. I think the current solution is cleaner.)

I am getting the same error, I’m assuming the API changed.

Note users facing this issue can temporarily use code in https://github.com/jamalex/notion-py/pull/10 while it is merged.

cd parent-directory-where-notion-py-is-checked-out
cd notion-py
git fetch upstream pull/10/head:marfixz
git checkout marfixz

Change from “searchPagesWithParent” to “queryCollection” which requires at least JSON data “collectionId”, “collectionViewId” and “loader” now. I try to send a post request to the /api/v3/queryCollection which returns a similar output as before data structure.

For me I simply save the “collectionViewId” into the “NotionClient” class and and hard-code the “loader” part for the “queryCollection” JSON data. Because the main goal for me is to get all the blocks inside the table and I did some modifications which works for me. Waiting for the update too!

https://github.com/wenshen35105/notion-py/commit/d0571c184bcb89efe346acab304a824bce3bf3aa