Axios post request error with 422 (Unprocessable Entity) from react

Active3 hr before
Viewed126 times

7 Answers


The problem is that you are expecting "query params" in the url (fastapi), not a json body.,Try working with Pydantic models, that way fastapi will be waiting a body in the request., Podcast 371: Exploring the magic of instant python refactoring with Sourcery , Thank you so much! So you mean that in fastapi i have to use pydantic model(json) instead of query params such as (email : str ..) ? Thanks for feedback i will deepdive more! – LCW Jul 14 at 15:22

def create_users(email: str, pwd: str, first_name: str, last_name: str, phone_number: str, city: str):
load more v

I am having trouble with my routes. the react front end keeps giving me POST http://localhost:3000/api/review/ 422 (Unprocessable Entity) when I try to submit reviews, and GET http://localhost:3000/api/review/movie/tt1825683 422 (Unprocessable Entity when I try to get reviews by imdbID.,Expected behavior, if applicable The routes should go the backend without issue.,It is a problem that the server can't response correctly, instead of an issue of axios. Please look for help in stackoverflow., Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

createReview: review => {
      const data = {
         data: review
      return'/api/review/', data);

   showMovieReviews: id => {
      return axios.get('/api/review/movie/' + id);
showCommentsByReview: id => {
   return axios.get('/api/comment/review/' + id);
load more v

The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions. ,© 2005-2021 Mozilla and individual contributors. Content is available under these licenses.,HTTP response status codes,422 Unprocessable Entity

422 Unprocessable Entity

import axios from "axios";
load more v

Fortunately, the solution is simple. When you access the error data, use error.response instead of error in your catch block, this way:,Recently I started integrating a bootstrap template with the Laravel backend. And one thing that made me suffer a lot is the ajax backend validation. Two errors often occur when you handle ajax requests with Laravel: 419 and 422.,This error occurs when your backend validation fails. If you let Laravel refresh your page after POST request, you get errors in @errors directive and stuff, but usually you want to handle it via ajax either because you care about user experience, or you use a frontend framework such as React or Vue. Or even both.,Suppose you validate your form with an email and password input fields:

<meta name="csrf-token" content="{{ csrf_token() }}" />
load more v

I would give up on the JSON format though and just append it to the end of the URL as I suggested the first time.,The 422 is that Canvas couldn't make sense out of your request. At first glance (without testing or looking at the documentation for other issues), I see that you are not sending the header to accept content-type: application/json.That is necessary if you use JSON. For PUT, I've had better success if I make it part of the query string and don't mess with the body.,Sorry for the non-certainty in the answer. I've got a lot of things I'm trying to manage right now., Getting 422 (Unprocessable Entity) error when loading custom JavaScript in Canvas Developers Group 08-03-2020


I am trying to call Canvas api to update on gradebook custom column from javascript.  There's no problem when I use GET to retrieve information from gb API, but I ran into ' 422 Unprocessable Entity' when calling PUT or DELETE to update. I tried to convert to JSON format to pass in data during PUT call, still resulted in same status code.  Can anyone throw me idea what the error be possible caused?   Thanks!

422 Unprocessable Entity

I’m using Laravel sanctum to use Rest API’s for Laravel Token based authentication and when I send the request to server using axios to the ‘/register’ route it returns a 422 error code .,i managed to create a user with tinker and i can log in and logout but it returns a 422 when i try to register a new user,and the Register Controller is by using the laravel ui –auth package and it looks like this, Receive currency prices and perform calculations on prices

I’m using Laravel sanctum to use Rest API’s for Laravel Token based authentication and when I send the request to server using axios to the ‘/register’ route it returns a 422 error code .

const handleRegister = async (e) => {

   axios.defaults.withCredentials = true
   axios.get(`${hostName}/sanctum/csrf-cookie`).then((res) => {
         .post(`${hostName}/register`, {
            name: 'admin',
            email: '[email protected]',
            password: 'user',
         .then((res) => {
            console.log('account created')
load more v

Other "unprocessable-entity" queries related to "Axios post request error with 422 (Unprocessable Entity) from react"