How do I get a list of all users from the API?

I see that I can get a list of users using the API using http://discourse.example.net/admin/users.json, but I get only 100 users and I don’t know how the paging for that works? The interface doesn’t seem to display more than 100 users if you go to the admin part.

There is no paging.
There is no scrolling.
Currently the only way to get more is to use “Export” :sadpanda:

sad panda indeed :frowning: The exported list doesn’t include the same data, and the way it happens makes it hard to grab programatically.

Any idea if paging for users is wanted by anyone else and if it is something that may be implemented at some stage?

Yes :smile:

No idea.

Any thought if this will be fixed/expanded? We really need API access to access our user lists. Limiting at 100 just doesn’t make sense.

Has this been addressed? This would be really useful to my user import script

I’d also love to see this, to use in scripts that process the whole user base in some way, like this:

Whilst not immediately obvious…

It is possible to get a list of all users via the groups API endpoint available to admins.

You’ll have to iterate over the following groups:

  • trust_level_0
  • trust_level_1
  • trust_level_2
  • trust_level_3
  • trust_level_4

But they do support both limit and offset parameters:

/groups/trust_level_0/members.json?limit=50&offset=50

This is a great workaround, but begs the question: Is there a reason these parameters are not supported on /users.json ?

It was recently noted that you only need to iterate trust_level_0:

So this API doesn’t give emails too. This means that I would have to get the whole list then interate through and pull each user individually to get all the appropriate info (admin, moderator, etc…) Is that correct

Yes I believe that is correct. I don’t think paging has been added yet to /admin/users.json.

Sorry the reply so late but that’s the first search result for “get list of all users discourse”…

You can implement read-only endpoints with the Data Explorer plugin.

  • Install the plugin
  • Create your query, with inputs if needed
  • Issue a POST request on /admin/plugins/explorer/queries/[id]/run (with [id] being your query ID)

You can also implement paging with limit/offset inputs I guess, but never tried.

For example, I’m using it to check if a given OAuth user ID is already registered on my instance through discourse-oauth2-basic.

간단히 업데이트된 답변: 페이지네이션된 사용자 목록은 두 가지 방식으로 제공됩니다:

  1. 공개 사용자 목록 — "디렉터리 목록"으로 제공됩니다.
  2. "플래그"별 사용자 목록 — URL의 {flag}는 Enum 값으로 대체되어야 합니다.

감사합니다,
ABK

안녕하세요

"flag"별 사용자 목록

모든 사용자를 가져올 수 있는 flag가 있나요? 예를 들어 https://{defaultHost}/admin/users/list/all.json 처럼요.

이 엔드포인트를 사용하여 모든 사용자를 가져오지 못했습니다. 이유가 있을까요?

조금 해킹적인 방식이지만, 내 환경에서는 잘 동작하는 또 다른 해결책:

/admin/users/list/active.json?show_emails=true&page=${page}

“active” 대신 “new” 플래그를 사용하면 모든 사용자를 가져올 수 있습니다. created 필드를 오름차순으로 정렬하면 가장 오래된 사용자부터 최신 사용자 순으로 모든 사용자가 표시됩니다. 사용자가 많을 경우 요청 크기가 지나치게 커질 수 있으므로, 모든 사용자를 가져오려면 여전히 페이지네이션을 사용해야 합니다.

/admin/users/list/new?asc=true&order=created&page=0

참고로:

    for page in itertools.count(start=1):
        userlist = api_get(f"admin/users/list/new.json?page={page}")
        if not userlist:
            break
        for user in userlist:
            print(f"{user['id']:5} {user['username']}")