Home > Enterprise >  Correct usage of data/body with axios in node.js
Correct usage of data/body with axios in node.js

Time:02-19

I get the error 'NOT_FOUND' with the error code of 404 when trying this code:

    axios.get(`https://api.exchange.bitpanda.com/public/v1/account/deposit/crypto`, {
      headers: {
        'content-type': 'application/json',
        'Authorization': 'Bearer api_key'
      },
      data: {
        "currency": "BTC"
      }
    })
    .then(function (response) {
      console.log(response.data)
    })
    .catch(function (error) {
      console.log(error.response.data);
      console.log(error.response.status);
    })

For some reason there are no examples in node.js

Picture of documentation

Bitpanda api documentation

CodePudding user response:

You get 404 because request to https://api.exchange.bitpanda.com/public/v1/account/deposit/crypto should be POST not GET as per the documentation

 axios.post(REST_OF_THE_CODE_HERE);

Also strutcture your request differently, read on how axios works here

const headers = 
 {
    'content-type': 'application/json',
    'Authorization': 'Bearer api_key'
 }

axios.post(URL, payload, { headers: headers})
      .then(function (response) {
        console.log(response.data)
      })
     .catch(function (error) {
        console.log(error.response.data);
        console.log(error.response.status);
     })
  • Related