<p dir="auto">Here is error:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/1636250/109177801-e079b280-7790-11eb-8fce-50257e88090a.png"><img src="https://user-images.githubusercontent.com/1636250/109177801-e079b280-7790-11eb-8fce-50257e88090a.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">Python 3.7.8<br>
fastapi 0.63.0</p>
<p dir="auto">Run configuration:<br>
<code class="notranslate">uvicorn.run("app:app", host="0.0.0.0", port=port, reload=True)</code></p>
<p dir="auto">I think the error is in the path here is console log:<br>
<code class="notranslate">127.0.0.1:54913 - "GET /api/v1/api/v1/openapi.json HTTP/1.1" 404 Not Found</code><br>
Here is double path: /api/v1/<strong>api/v1/</strong></p>
<p dir="auto">Doc path is wrong <a href="http://localhost:8080/docs" rel="nofollow">http://localhost:8080/docs</a> I expect it to be: <a href="http://localhost:8080/api/v1/docs" rel="nofollow">http://localhost:8080/api/v1/docs</a></p>
<p dir="auto">Here is the test code to reproduce 'test_app.py' file:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import uvicorn
import json
from fastapi import FastAPI, APIRouter, Response
from fastapi.responses import RedirectResponse

app = FastAPI(title=&quot;Root path test&quot;, root_path=&quot;/api/v1&quot;)

@app.post(&quot;/test-call &quot;, tags=[&quot;test&quot;])
def ping():
    return Response(
        json.dumps(dict(ping='pong')), 
        headers={'Content-Type':'application/json'})

@app.get(&quot;/&quot;)
def read_typer():
    return RedirectResponse('/docs')


if __name__ == &quot;__main__&quot;:
    uvicorn.run(&quot;test_app:app&quot;, host=&quot;0.0.0.0&quot;, port=8080, reload=True)"><pre class="notranslate"><code class="notranslate">import uvicorn
import json
from fastapi import FastAPI, APIRouter, Response
from fastapi.responses import RedirectResponse

app = FastAPI(title="Root path test", root_path="/api/v1")

@app.post("/test-call ", tags=["test"])
def ping():
    return Response(
        json.dumps(dict(ping='pong')), 
        headers={'Content-Type':'application/json'})

@app.get("/")
def read_typer():
    return RedirectResponse('/docs')


if __name__ == "__main__":
    uvicorn.run("test_app:app", host="0.0.0.0", port=8080, reload=True)
</code></pre></div>
<p dir="auto">Hello,</p>
<p dir="auto">I am following to fastAPI callbacks here : <a href="https://fastapi.tiangolo.com/advanced/openapi-callbacks/" rel="nofollow">https://fastapi.tiangolo.com/advanced/openapi-callbacks/</a> to try to set up slack alerts in one of my projects.</p>
<p dir="auto">My goal is to sending a slack message whenever the API request failed. My code looks like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from typing import Optional

from fastapi import APIRouter, FastAPI
from pydantic import BaseModel, HttpUrl

app = FastAPI()


class Invoice(BaseModel):
    id: str
    title: Optional[str] = None
    customer: str
    total: float


class InvoiceEvent(BaseModel):
    description: str
    paid: bool


class InvoiceEventReceived(BaseModel):
    ok: bool


invoices_callback_router = APIRouter()


@invoices_callback_router.post(&quot;&quot;, response_model=InvoiceEventReceived)
def invoice_notification(body: InvoiceEvent):
    return {&quot;okay&quot;: &quot;yes&quot;}


@app.post(&quot;/invoices/&quot;, callbacks=invoices_callback_router.routes)
def create_invoice(invoice: Invoice, callback_url: Optional[HttpUrl] = None):
    return {&quot;msg&quot;: &quot;Invoice received&quot;}"><pre class="notranslate"><code class="notranslate">from typing import Optional

from fastapi import APIRouter, FastAPI
from pydantic import BaseModel, HttpUrl

app = FastAPI()


class Invoice(BaseModel):
    id: str
    title: Optional[str] = None
    customer: str
    total: float


class InvoiceEvent(BaseModel):
    description: str
    paid: bool


class InvoiceEventReceived(BaseModel):
    ok: bool


invoices_callback_router = APIRouter()


@invoices_callback_router.post("", response_model=InvoiceEventReceived)
def invoice_notification(body: InvoiceEvent):
    return {"okay": "yes"}


@app.post("/invoices/", callbacks=invoices_callback_router.routes)
def create_invoice(invoice: Invoice, callback_url: Optional[HttpUrl] = None):
    return {"msg": "Invoice received"}
</code></pre></div>
<p dir="auto">I would input slack webhooks link in callback_url, however, I am not very sure where to put payload for the callback_url, anyone could help ?</p>