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

Hi there,

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

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?

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.

2 Likes

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? :thinking:

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

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

Can you share the exact code you are using?

4 Likes

Well that explains it then :slight_smile:

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 :expressionless:

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