[Python] How can I make Notion Webhooks with Python FastAPI?

Discussão em 'Python' iniciado por Stack, Junho 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am making Webhook in Notion and I'm using Python FastAPI Library.

    Here is my code, router.py:

    router = APIRouter()
    @router.post("/webhook")
    async def handle_webhook(request: Request):
    print(await request.json())
    return {"status": "received"}


    and main.py:

    from fastapi import FastAPI, Request
    from fastapi.templating import Jinja2Templates
    from fastapi.staticfiles import StaticFiles

    from router import router as web_router

    app = FastAPI()
    app.mount("/static", StaticFiles(directory="src/web/resources"), name="static")

    app.include_router(web_router)

    if __name__ == "__main__":
    import uvicorn
    uvicorn.run("main:app", host="0.0.0.0", port=8080, reload=True)


    and I'm running this server with Azure Service, so if I send webhook post in curl, it works well. But if I upload this url to Notion Button Webhooks, I get 'Failed to run button.' If I use webhook.site, it works well too. What did I wrong?

    Edit) If I test with my curl, there is FastAPI log on my server, but If I press button in notion, there is no log. That means notion didn't request at first.

    Continue reading...

Compartilhe esta Página