Hey everyone! I’m having trouble getting my Notion workspace content through their API. I’ve set up an integration and connected the pages I want to access. Here’s the Python code I’m using:
But I’m getting a 401 error saying the API token is invalid. I’m pretty sure my token is correct and has the right permissions. Am I missing something? Maybe the API version is wrong? Any help would be awesome!
I’ve been using the Notion API for a while now, and I can tell you it can be a bit finicky sometimes. From what I see in your code, there are a couple of things you might want to try.
First off, for fetching page content, you should be using a GET request instead of POST. That could be why you’re getting that 401 error. Try changing your get_page_content method to use self.session.get(url) instead.
Also, make sure you’ve actually given your integration access to the specific page you’re trying to fetch. Go to the page in Notion, click the ‘…’ menu at the top right, then ‘Add connections’ and select your integration.
If you’re still having trouble after that, try logging the full response from the API, not just the JSON. Sometimes there’s additional error info in the headers or status code that can help pinpoint the issue.
Hope this helps! Let us know if you get it working.
I encountered a similar issue when first working with the Notion API. One thing to double-check is that you’ve actually shared the specific page with your integration. Even with a valid token, you won’t be able to access pages that haven’t been explicitly shared.
To do this, go to the page in Notion, click ‘Share’ in the top right, and make sure your integration is listed there. If not, add it.
Also, for debugging, try making a simple request to the /users/me endpoint. If that works, it confirms your authentication is correct, narrowing down the problem to permissions or the specific page ID.
hey mate, i had a similar issue. check ur token again, sometimes it’s easy to miss a character. also, try using the ‘get’ method instead of ‘post’ for fetching content. the api version looks fine tho. if that doesn’t work, maybe try regenerating the token? good luck!