0

I'm trying to create a new user on my forums (Flarum) from a external script using VueJS + Axios, but, I keep getting 405 error.

Log:

/api/users 405 (Method Not Allowed)
#:1 Failed to load /api/users: Response for preflight has invalid HTTP status code 405.

Code i'm using

axios.post(forumAPI, {
    data: {
        attributes: {
            username: this.data.attributes.username,
            password: this.data.attributes.password,
            email: this.data.attributes.email,
        }
    },
    headers: {
        'Authorization': 'Token XXXXX',
        'Content-Type': 'application/vnd.api+json'
    },
})
.then(function (response) {
    store.dispatch('login', this.data.attributes).then(() => {
        this.$router.push(this.$route.query.redirect || '/dev');
        this.loading = false;
        this.hideModal();
    })
})
.catch(function (error) {
    console.log(error);
    _this.loading = false;
})

I need post a json like this one:

{"data":
     { "attributes":
          {
              "username":"mickey",
              "email":"mickey@disney.com", 
              "password":"hellokitty"
          }
      }
}

I know theres something wrong with my sintax, but, I can't figure it out.

Any solutions around here?

Thanks!

Lós
  • 3
  • 1
  • Simple; your API is not set up for CORS access – Phil Feb 07 '18 at 23:22
  • Your API should be able to handle `OPTIONS` requests, [a.k.a. preflight requests](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request) for cross-origin communication. – JJWesterkamp Feb 07 '18 at 23:27
  • @Phil, it was using CORS and returning me CORS error, but, I disabled it for remote development propourse. Do you think it still disabling my remote consuming from api? – Lós Feb 07 '18 at 23:27
  • I have no idea what that means. You can limit CORS access to specific hosts via the `Access-Control-Allow-Origin` response header – Phil Feb 07 '18 at 23:29

0 Answers0