http://forums.my-domain.net/users.json returns a 404
Is the documentation outdated?
The discussion revolves around creating users via the Discourse REST API. NubeBuster initially encountered issues with a 404 error and a 204 No Content response when trying to create a user, questioning if the documentation was outdated. JammyDodger confirmed the API works and suggested checking API key permissions, noting that the user might lack the necessary rights. NubeBuster shared their code, which uses a POST request with URLSearchParams and an API key, but still faced issues. pfaffman asked about the use case, to which NubeBuster explained they want to bind users to Minecraft accounts to prevent spam. Finally, NubeBuster resolved the issue by changing the URL from HTTP to HTTPS, confirming the API call worked.
http://forums.my-domain.net/users.json returns a 404
Is the documentation outdated?
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?
After changing the url to 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
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
What problem are you solving by creating users via the API?
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.
I’ve solved the problem. The url had to be https not http.