Admin/users/list/ REST API not working

AI-generated summary

The user lenny1 is experiencing an error when trying to access the /admin/users/list/active.json REST API endpoint, receiving a “The requested URL or resource could not be found” message. Despite the API key working for other endpoints like /latest.json, the admin endpoint fails. Arkshine clarifies that the API key must have admin permissions, and lenny1 confirms the key was created for a non-admin user, even with “All Users” scope. JammyDodger confirms that admin-level access is required for admin endpoints. lenny1 suggests the error message is misleading and should indicate permission issues rather than a missing resource.

I tried to get active users but it returned error message “The requested URL or resource could not be found”.
My java codes:

	
	     Map<String, String> headers = new HashMap<>();		
	     headers.put("Content-Type", "application/json");
	     headers.put("Api-Key", apiKey);
	     headers.put("Api-Username", userName);	    
		 headers.put("Accept", "application/json");
		
		return Unirest.get("https://my-discourse-server/admin/users/list/active.json")
				.headers(headers)
				.asString()
				.getBody()
				.toString();

I am certain that nothing wrong with my api key because it works for other query for instance “https://my-discourse-server/latest.json” returned the correct result.

Besides, If I login discourse as admin and type in url “https://my-discourse-server/admin/users/list/active.json” in the web browser it did list all the active users.

Whats wrong?

My discourse version is 3.1.0.beta2

Hi,

What User Level and Scope did you use for that API key?

If you are sure there is no typo, you might have created one with a non-admin single user.

Single User, Global. Yes. non-admin
So the user must be a adminstrator?
I tried “All Users”, Global also has same issue.

To access the admin areas, you would need an API key with admin permissions. :+1:

IMO, the error message is misleading. It should be more meaningful about the permission such as “Invalid credential”.