I'm trying to read the comments on a database entry in notion but I can't figure out how I need to make the request.
import requests
_url = 'https://api.notion.com/v1/comments'
_headers = {"Authorization": _auth,
"Notion-Version": "2021-08-16"}
_data = {'block_id': _page_id}
_results = requests.post(_url, headers=_headers, data=json.dumps(_data))
_data = _results.json()
These results I get back are something like this:
{u'code': u'validation_error',
u'message': u'body failed validation. Fix one:\nbody.parent should be defined, instead was `undefined`.\nbody.discussion_id should be defined, instead was `undefined`.',
u'object': u'error',
u'status': 400}
I'm trying to follow the docs here https://developers.notion.com/reference/retrieve-a-comment but I'm not sure how it translates into python.
Has anyone managed to do this?
If you are reading/getting data from the API, you should use
GET
, notPOST
.To translate the API to Python code, you will do something like this. Notice that the
block id
is a query parameter not in the request body.You also need to ensure that you have added the integration to the notion page.
Run the code, you will get the response like this, (in my case, I don't have any comments on the page).