An attempt to use axios for API endpoint query
P粉340264283
P粉340264283 2023-09-09 19:50:48
0
1
619

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粉340264283
P粉340264283

reply all(1)
P粉056618053

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);
  })
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template