Value is not a valid dict when posting JSON data through Postman to FastAPI backend

When defining your payload Body parameter like this:

payload: dict = Body(...)

and since it is the only Body parameter in your endpoint, FastAPI will expect a body like:

{
  "some key": "some value"
}

Since you have a single body parameter, you could also use the special Body parameter embed:

payload: dict = Body(..., embed=True)

in which case, FastAPI would expect a body like:

{
  "payload": {"some key": "some value"}
}

Please have a look at this answer, as well as this answer and this answer for more details.

When sending the request through Postman

Also, the 422 Unprocessable Entity error shows that the body received doesn’t match the expected format. Hence, please make sure you are posting the request body through Postman in the right way. That is, go to Body -> raw, and select JSON from the dropdown list to indicate the format of your data. Please take a look at the answers here and here for more details.

Leave a Comment