Admin/users/list/ REST API not working

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.

3 Likes

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:

1 Like

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

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