# Cannot create new users

**URL:** <https://community.auth0.com/t/cannot-create-new-users/67889>\
**Category:** Get Help\
**Created:** [August 13, 2021, 8:02am UTC](https://community.auth0.com/t/cannot-create-new-users/67889 "2021-08-13T08:02:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aus-it-orders](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/aus-it-orders/32/12732_2.png) [@aus-it-orders](https://community.auth0.com/u/aus-it-orders)\
**Post date:** [August 13, 2021, 8:02am UTC](https://community.auth0.com/t/cannot-create-new-users/67889/1 "2021-08-13T08:02:55Z")

</div>

I amhaving considerable issues getting a seemingly basic operation to work. I don’t know why this is made so difficult, or why the docs are so disparate but here we are…

I have an endpoint that creates basic users on registration, so that when we launch they don’t have to sign up or anything like that. I am getting the access token from the management API after having created another machine-to-machine application. I am then passing that token into another request object to create the user.

I am getting 401 from the axios request and “invalid URI” from the request request.

How can I make this work?

```auto
var request = require("request");
const axios = require("axios");
var qs = require('qs');
var tokenOptions = { method: 'POST',

    url: 'https://<dev>.au.auth0.com/oauth/token',
    headers: { 'content-type': 'application/json' },
    body: '{"client_id":"<id>","client_secret":"<secre>","audience":"https://<sub>.au.auth0.com/api/v2/","grant_type":"client_credentials"}'

};

request(tokenOptions, function (tokenError, response, tokenbody) {

    if (tokenError) {
        throw new Error(tokenError);
    }

    const bodyJson = JSON.parse(tokenbody);
    console.log(bodyJson);
    var createClientOptions = { method: 'POST',
        url: 'https://<sub>.au.auth0.com/api/v2/users',
        headers: {
            'Content-Type': 'application/json',
            'authorization': `Bearer ${bodyJson.access_token}`,
        },
        body: {
            "email": "<email>@gmail.com",
            "blocked": false,
            "email_verified": false,
            "connection": "Initial-Connection",
            "password": "secret",
            "verify_email": true,
            "username": "johndoe",
        },
    }

    request(JSON.stringify(createClientOptions), function(Error, some, createClientResponse){
        console.log(Error);
        console.log(some);
        console.log(createClientResponse);
    })

 
    axios.post('https://<sub>.auth0.com/api/v2/users', qs.stringify(createClientOptions))
    .then(createClientResponse => {
        console.log(createClientResponse.data);
    })
    .catch(error => {
        console.log(error);
    });

});

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 13, 2021, 6:23pm UTC](https://community.auth0.com/t/cannot-create-new-users/67889/3 "2021-08-13T18:23:42Z")

</div>

Hi @aus-it-orders,

Have considered using our [auth0 node library](https://github.com/auth0/node-auth0)? The management client makes it dead simple. I would recommend it if you are having trouble making your own requests against the management API.

I am curious, why are using using both _axios_ and _request_ ?

Here is a code snippet that should work.

```auto
const ManagementClient = require('auth0').ManagementClient;
const auth0 = new ManagementClient({
  domain: '{YOUR_ACCOUNT}.auth0.com',
  clientId: '{YOUR_NON_INTERACTIVE_CLIENT_ID}',
  clientSecret: '{YOUR_NON_INTERACTIVE_CLIENT_SECRET}',
  scope: 'update:users'
});

const data = {
  "email": "<email>@gmail.com",
  "blocked": false,
  "email_verified": false,
  "connection": "Initial-Connection",
  "password": "secret",
  "verify_email": true,
  "username": "johndoe"
}
  
auth0.createUser(data, function (err) {
  if (err) {
    // Handle error.
  console.log(err)
  }

  // User created.
});

```

---

<div class="post-metadata">

**Author:** ![aus-it-orders](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/aus-it-orders/32/12732_2.png) [@aus-it-orders](https://community.auth0.com/u/aus-it-orders)\
**Post date:** [August 16, 2021, 4:58am UTC](https://community.auth0.com/t/cannot-create-new-users/67889/4 "2021-08-16T04:58:45Z")

</div>

Hi Dan,

Thanks for your response.

I had thought of using that but tbh the docs are not very clear about what the difference is between the two methods and how to use Auth0 in this way. Now I see this is obviously the better and preferred option.

There seem to be two copies of the docs with one neatly organized in the link you have provided and the other smattered across tutorials and the getting started section on the website inside the accounts section. I suspect the link you provided is the new and improved documentation and I must say it is very nice indeed.

I’ve used request and axios because that is how the instructions are laid out in the application window on my Auth0 account, I too found that odd. See my previous comment about fractured documentation. I tried to use one or the other but had issues when not strictly following the documentation.

Thanks

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 16, 2021, 4:19pm UTC](https://community.auth0.com/t/cannot-create-new-users/67889/5 "2021-08-16T16:19:38Z")

</div>

If you can provide examples of the documentation issues I would be happy to pass the feedback along to our docs team.

---

<div class="post-metadata">

**Author:** ![aus-it-orders](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/aus-it-orders/32/12732_2.png) [@aus-it-orders](https://community.auth0.com/u/aus-it-orders)\
**Post date:** [August 17, 2021, 9:22am UTC](https://community.auth0.com/t/cannot-create-new-users/67889/6 "2021-08-17T09:22:20Z")

</div>

Sure, in the “Quick Start” section of the Machine 2 Machine applications:

 ![m2mquickstart](https://global.discourse-cdn.com/auth0/original/3X/3/8/383104611bf22a5fd3eb622c9dbd1ade118559b8.png)

Then just below it:

 ![m2mquickstart2](https://global.discourse-cdn.com/auth0/original/3X/0/c/0c9994c5b20bb52d5c3b235356723b807df66567.png)

Of course, the m2m application was created as a prerequisite to creating new users because I thought I would need to access the management API.

There is this documentation: [Auth0 Management API v2](https://auth0.com/docs/api/management/v2#!/Users/post_users)  
Then there is this documentation: [Create Users](https://auth0.com/docs/users/create-users)

* * *

Anyway, all of that aside it turns out that what I really need was to simply change the login type to password-less and eliminate the need for any of the above. Again, something that ought to be front of mind in the docs as passwords are outmoded.

I found a solution at this article: [Auth0 Passwordless Authentication | Medium](https://aishwaryabannimatti.medium.com/auth0-passwordless-email-authentication-react-app-e60619a747bd)

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 17, 2021, 7:05pm UTC](https://community.auth0.com/t/cannot-create-new-users/67889/7 "2021-08-17T19:05:06Z")

</div>

Thanks for the thorough feedback. We really appreciate it. I’ll take a look at this and pass along the relevant info to the teams who manage these code snippets. I agree, it’s odd that one uses request and one uses axios.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [September 1, 2021, 7:06pm UTC](https://community.auth0.com/t/cannot-create-new-users/67889/8 "2021-09-01T19:06:02Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
