0
votes

I'm calling a simple login API with POST request following are the params: Headers: Content-type: application/x-www-form-urlencoded Body: email: String password Error returned from server is:422 Unprocessable Entity

CODE:

  var formBody = new FormData();
formBody.set("email", "[email protected]");
formBody.set("password", "12345678");


const data = new URLSearchParams(new FormData(details));
return  dispatch => {
    dispatch(requestData());
    try {
        fetch(`${BASE_URL}users/sign_in`, {
            method: 'POST',
            // headers: Interceptor.getHeaders(),
            headers: {
                Accept:'application/json',
                'Content-Type': 'application/x-www-form-urlencoded'
              },
            //   body: formBody
             body: data

        })
            .then(res => res.json())
                .then(result=>
                {
                    if (result.success === false) {}
                }
                )


    } catch (error) {
        console.log('error',error)
        dispatch(failureData(error))
    }
}

Screenshot of code

1
you should add the code from the image to the question...Moshe Slavin
@MosheSlavin done, have a lookAhmad Zahid

1 Answers

0
votes

Got the answer, 422 is basically caused by semantic issue, in my case, Origin of my Request Header was going null.