# Creating users through RESTFUL Users API - Users.json got wiped

**URL:** https://meta.discourse.org/t/creating-users-through-restful-users-api-users-json-got-wiped/110362
**Category:** Development
**Tags:** rest-api
**Created:** [February 28, 2019, 4:15pm UTC](https://meta.discourse.org/t/creating-users-through-restful-users-api-users-json-got-wiped/110362 "2019-02-28T16:15:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ka0sdev](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ka0sdev/32/132296_2.png) [@ka0sdev](https://meta.discourse.org/u/ka0sdev)
#### Post date: [February 28, 2019, 4:15pm UTC](https://meta.discourse.org/t/creating-users-through-restful-users-api-users-json-got-wiped/110362/1 "2019-02-28T16:15:59Z")

</div>

Hi there,

I’m trying to create new users using the RESTful Users API using below code:

> [@kevincolten](#):
>
> const fetch = require(‘node-fetch’);  
> const FormData = require(‘form-data’);
> 
> const data = {  
> api\_key: ‘generated key’,  
> api\_username: ‘username’,  
> name: ‘Test User’,  
> email: ‘test@gmail.com’,  
> password: ‘hello12345’,  
> username: ‘testuser-0’  
> };
> 
> const formData = new FormData();  
> for (let key in data) {  
> formData.append(key, data[key]);  
> }
> 
> fetch(‘\<discourse-url\>/users.json’, {  
> method: ‘POST’,  
> body: formData  
> }).then(res =\> {  
> res.json().then(json =\> {  
> console.log(json);  
> }).catch(err =\> {  
> console.log(err);  
> });  
> }).catch(err =\> {  
> console.log(err);  
> });

This was working flawless yesterday, and now all of a sudden when going to my  
`<discourse-url>/users.json`

All I see is:  
`{"errors":["The requested URL or resource could not be found."],"error_type":"not_found"}`

For some reason the users.json got wiped, no idea why.

Is it possible to restore it? Or generate a new users.json somehow?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [February 28, 2019, 4:24pm UTC](https://meta.discourse.org/t/creating-users-through-restful-users-api-users-json-got-wiped/110362/2 "2019-02-28T16:24:50Z")

</div>

I don’t think `<discourse-url>/users.json` has ever worked. Are you thinking of `<discourse-url>/admin/users.json`?

If `<discourse-url>/admin/users.json` is returning a “not found” error, it probably means that your API key is incorrect.

---

<div class="post-metadata">

### Author: ![ka0sdev](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ka0sdev/32/132296_2.png) [@ka0sdev](https://meta.discourse.org/u/ka0sdev)
#### Post date: [February 28, 2019, 4:30pm UTC](https://meta.discourse.org/t/creating-users-through-restful-users-api-users-json-got-wiped/110362/3 "2019-02-28T16:30:42Z")

</div>

As the matter of fact /users.json was working yesterday and created the new accounts through Node.js so somehow it has existed. For the admin/users.json I get following return:

> { status: 404, error: ‘Not Found’ }

I’ve even regenerated a new API key and still the same result.

I’m a bit lost here to be honest, no idea why this behavior started, I mean I could take a backup and rebuild Discourse just to see if that will fix it, but it seems like a drastic measure.

Any suggestions? 🤔

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [February 28, 2019, 4:40pm UTC](https://meta.discourse.org/t/creating-users-through-restful-users-api-users-json-got-wiped/110362/4 "2019-02-28T16:40:43Z")

</div>

Oh I see, you are trying to **create** users, not list them. In that case ignore my previous post 😉

If you visit `<discourse-url>/users.json` in your browser, it will return that “not found” error. That is to be expected. Sending a POST request to that URL, along with all the necessary parameters, should work fine. The docs for the endpoint are here: [Discourse API Docs](https://docs.discourse.org/#tag/Users%2Fpaths%2F~1users%2Fpost)

Can you share the exact code you are using?

---

<div class="post-metadata">

### Author: ![ka0sdev](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ka0sdev/32/132296_2.png) [@ka0sdev](https://meta.discourse.org/u/ka0sdev)
#### Post date: [February 28, 2019, 5:11pm UTC](https://meta.discourse.org/t/creating-users-through-restful-users-api-users-json-got-wiped/110362/5 "2019-02-28T17:11:55Z")

</div>

Well that explains it then 🙂

I am using the exact same code as I quoted in the OP, which yesterday gave following response:

```
{ success: true,
  active: true,
  message:
   'Thanks for signing up. We will notify you when your account has been approved.',
  user_id: 5 }

```

And today I’m faced with this;

```
{ FetchError: invalid json response body at <discourse-url>/users reason: Unexpected end of JSON input
    at C:\Users\ka0sdev\NodeRobot\node_modules\node-fetch\lib\index.js:241:32
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
  message:
   'invalid json response body at <discourse-url>/users reason: Unexpected end of JSON input',
  type: 'invalid-json' }

```

Which is strange seeing as I haven’t exactly changed the code one bit, obviously it was adapted to my Discourse, I have removed the URL because the site is not in production and I want to avoid crawlers finding it through this site.

I just validated the json being parsed and apparently it’s not valid either, this is kind of beyond me seeing as it worked yesterday 😑

I have reworked the payload to include double quotations, but still I get invalid-json.
