# Create users using rest-api

**URL:** https://meta.discourse.org/t/create-users-using-rest-api/299525
**Category:** Development
**Tags:** rest-api
**Created:** [March 15, 2024, 1:28pm UTC](https://meta.discourse.org/t/create-users-using-rest-api/299525 "2024-03-15T13:28:39Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![NubeBuster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nubebuster/32/371096_2.png) [@NubeBuster](https://meta.discourse.org/u/NubeBuster)
#### Post date: [March 15, 2024, 1:28pm UTC](https://meta.discourse.org/t/create-users-using-rest-api/299525/1 "2024-03-15T13:28:39Z")

</div>

> **[Discourse API Docs](https://docs.discourse.org/#tag/Users/operation/createUser)**

[http://forums.my-domain.net/users.json](http://forums.my-domain.net/users.json) returns a 404

Is the documentation outdated?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [March 15, 2024, 1:40pm UTC](https://meta.discourse.org/t/create-users-using-rest-api/299525/2 "2024-03-15T13:40:10Z")

</div>

Hello and welcome @NubeBuster 🙂

I’ve just tried this on my test site and I have successfully created a user, so I believe it’s up-to-date and functional.

Are you using an API key and user with adequate permissions?

---

<div class="post-metadata">

### Author: ![NubeBuster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nubebuster/32/371096_2.png) [@NubeBuster](https://meta.discourse.org/u/NubeBuster)
#### Post date: [March 15, 2024, 1:53pm UTC](https://meta.discourse.org/t/create-users-using-rest-api/299525/3 "2024-03-15T13:53:29Z")

</div>

After changing the url to [http://forums.my-domain.net/users](http://forums.my-domain.net/users) instead of .json I get http “204 no content” back.

When creating the api key I don’t see the create route in granular mode. So I’ve set it to global. Perhaps the issue is indeed that I don’t have permission. Do I need to create the key as system user? Currently I am using the admin user with “Discourse Admin” group

```ts

const data = create = {
    name: "TestName",
    email: "test@mydomain.com",
    password: "TestTestTest",
    username: "TestUsername",
    active: true,
    approved: true,
    "user_fields[1]": true,
    external_ids: {
      uuid: "some uuid",
    },
};
//URLSearchParams is the same as FormData
const formData = new URLSearchParams();
for (const key in data) {
  formData.append(key, data[key]);
}

const url = BASE_URL + "users";
const response = await fetch(url, {
  method: "POST",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded",
     Accept: "application/json",
     "Api-Key": API_KEY,
     "Api-Username": API_USER,
  },
  body: formData,
 });

console.log("Response: " + response.status + ": " + response.statusText);

```

Perhaps you could show me the command/code you use to send the request? @JammyDodger

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 15, 2024, 2:03pm UTC](https://meta.discourse.org/t/create-users-using-rest-api/299525/4 "2024-03-15T14:03:32Z")

</div>

What problem are you solving by creating users via the API?

---

<div class="post-metadata">

### Author: ![NubeBuster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nubebuster/32/371096_2.png) [@NubeBuster](https://meta.discourse.org/u/NubeBuster)
#### Post date: [March 15, 2024, 2:15pm UTC](https://meta.discourse.org/t/create-users-using-rest-api/299525/5 "2024-03-15T14:15:03Z")

</div>

I want users to be bound to a minecraft account. Only visitors of my minecraft server can sign up. They will do so by performing an in-game command with their email address. Their username and display name will be their ingame name.

This is to prevent spam accounts, and to bind the username so it’s the same as their game tag.

---

<div class="post-metadata">

### Author: ![NubeBuster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nubebuster/32/371096_2.png) [@NubeBuster](https://meta.discourse.org/u/NubeBuster)
#### Post date: [March 15, 2024, 2:23pm UTC](https://meta.discourse.org/t/create-users-using-rest-api/299525/6 "2024-03-15T14:23:09Z")

</div>

I’ve solved the problem. The url had to be https not http.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [April 14, 2024, 2:23pm UTC](https://meta.discourse.org/t/create-users-using-rest-api/299525/7 "2024-04-14T14:23:23Z")

</div>

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