0
votes

I am using node js server on my local environment, I have tested the APIs with postman and it is working as expected. Now I am working on creating front-end with the help on react js. I am having trouble with Axios.get method with parameters. As it is not returning the same error as it does with postman. I am sending data in x-www-form-urlencoded in postman , and this is what i am trying to achieve with Axios in react js.

let config = {
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            params: {
              eth_wallet: this.state.deposit_address
            },
          }
        axios.get(methods.verify_eth_transaction, config)
        .then((result)=>{
            console.log(result)
        })
        .catch((err)=>{
            console.log(err)
        })

I have also tried

 axios.get(methods.verify_eth_transaction, qs.stringify(this.state.deposit_address), config)
        .then((result)=>{
            console.log(result)
        })
        .catch((err)=>{
            console.log(err)
        })

It should return "Unable to find a deposit. Please try again." as it is in postman get call. But it is returning "Wallet not found", making me believe that there is something wrong with the way i am sending parameters in my request.

And this is how my node server use the parameters.

Bridge.find({ eth_wallet: { $in: req.body.eth_wallet } }, (err, account) => {
//
//
})
1

1 Answers

0
votes

Axios GET method doesnt take a body object. You can either change your API route to use POST method or you can change the way you are sending your params like this:

axios.get(url, {
  params: {
    eth_wallet: this.state.deposit_address
  }
});

Hope this helps!!