Hey guys, I’m stuck with a Notion API issue. I’m trying to upload images to my Notion page using the unofficial API (since the official one doesn’t support local file uploads). I got the connection working with my token_v2 and even created an image block. But when I try to actually upload the image, I get a 403 Forbidden error.
Here’s a simplified version of what I’m doing:
from notion_client import NotionClient
def add_image_to_page():
client = NotionClient(token_v2='my_secret_token')
page = client.get_block('my_page_url')
new_image = page.children.add_new('image')
new_image.upload_file('path/to/my/image.jpg')
new_image.move_to(page.children[1], 'before')
page.children[0].remove()
The error happens on the upload_file
line. Any ideas what I’m doing wrong? I’ve been banging my head against this for days now. Help would be much appreciated!
I’ve run into this 403 error before when working with Notion’s unofficial API. One thing that helped me was ensuring I had the latest version of the notion_client library installed. Sometimes older versions can cause compatibility issues.
Another potential solution is to check your Notion workspace permissions. Make sure the account associated with your token_v2 has full edit access to the page you’re trying to modify.
If those don’t work, you might want to consider using a different method for image uploads. I’ve had success using Notion’s public API to create an external image block, then updating it with a URL. It’s a bit more roundabout, but it’s more reliable in my experience.
Lastly, don’t forget to handle potential rate limiting. Adding a short sleep between API calls can sometimes resolve unexpected errors.
hey jess, ive had similar issues. have u tried using a different token? sometimes the token_v2 can expire or get revoked. also, double check ur file path and permissions. if that doesnt work, maybe try uploading to a temp url first and then linking it in notion. hope this helps!
I’ve encountered this issue before, and it can be quite frustrating. One thing that worked for me was using the ‘notion-py’ library instead of ‘notion-client’. It seems to handle image uploads more reliably.
Another approach you might consider is base64 encoding your image and sending it as a string. This bypasses some of the upload restrictions.
If you’re set on using the current method, try adding a delay between creating the image block and uploading the file. Sometimes Notion’s API needs a moment to register the new block before accepting uploads.
Lastly, ensure your token has the necessary permissions. You might need to regenerate it with full access to the workspace where you’re trying to upload.