0

Running into a bad request 400 error when using axios call to endpoint ending in .php.

Code for the call looks like this

const API = {
  userLogin: function () {
    const email = "test@email";
    const password = "Test1234";
    return axios({
      method: "POST",
      body: {
        email,
        password,
      },
      headers: {
        "Content-Type": "application/json",
      },
      url: "url ends in /user-login.php",
    });
  },
};

the email and password are different in my actual code as are is the URL, but they were giving to me as body params to pass to the endpoint. The instructions state to make the API call method "POST" and pass email and password as body params.

here is the error response i get in the picture included. enter image description here

the top error is with using Fetch, and the Error that is expanded is with that axios call above. Any suggestions?

1 Answers1

0

Check the Axios documentation, https://github.com/axios/axios#request-config You probably want to put the variables you have in the body section in your code as data instead, i.e. data: { email, password, },

grimli
  • 51
  • 1
  • tried it with data as well and it still does not work – Matt Volonnino Feb 22 '21 at 22:21
  • Well, according to the docs, `data` is the data to be sent as the request body. Are you getting the same error message? If so maybe you need to check with the people who made the API if you need to pass additional parameters. – grimli Feb 23 '21 at 13:28