Home  >  Q&A  >  body text

An attempt to use axios for API endpoint query

Hi, I'm trying to get this mod.io example to work. Here is a curl example they gave

curl -X POST https://api.mod.io/v1/oauth/emailrequest \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'api_key=0d0ba6756d032246f1299f8c01abc424' \
  -d 'email=john.snow@westeros.com'

I'm trying to add this to my Vue JS application but it returns a 401 error. Can anyone see what's wrong?

methods: {
loginUser() {
  const headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
  }
  console.log(this.email) //Works
  const data = {
    api_key: "0d0ba6756d032246f1299f8c01abc424",
    email: this.email
  }
  axios
  .post('https://api.mod.io/v1/oauth/emailrequest', data, {
    headers: headers
  })
  .then(response => {
    console.log(response);
  })
  .catch((error) => {
    console.log(error);
  })
}

The API and email are from the documentation, so feel free to give it a try. This is the problem I have

Could it be that my localhost doesn't have SSL?

P粉340264283P粉340264283405 days ago593

reply all(1)I'll reply

  • P粉056618053

    P粉0566180532023-09-10 16:25:05

    I know I am very close to success....

    const headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
      const data = "api_key=0d0ba6756d032246f1299f8c01abc424&email="+this.email;
      
      axios
      .post('https://api.mod.io/v1/oauth/emailrequest', data, {
        headers: headers
      })
      .then(response => {
        console.log(response);
      })
      .catch((error) => {
        console.log(error);
      })

    reply
    0
  • Cancelreply