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.

「いいね!」 4

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?

「いいね!」 1

Yes :smile:

No idea.

「いいね!」 1

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.

「いいね!」 5

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

「いいね!」 2

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

「いいね!」 1

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
「いいね!」 7

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

「いいね!」 1

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

「いいね!」 4

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.

「いいね!」 2

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.

「いいね!」 4

簡潔に更新した回答:ページャブルなユーザーリストは、以下の2つの方法で取得できます。

  1. ユーザーの公開リスト(「ディレクトリ一覧」として)
  2. フラグによるユーザーリスト(URL内の{flag}を列挙型に置き換えて使用)

では、よろしくお願いいたします。
ABK

「いいね!」 4

こんにちは。

「フラグ」別のユーザー一覧

について、すべてのユーザーを取得するためのフラグはありますか?例えば、https://{defaultHost}/admin/users/list/all.json のようなものです。

「いいね!」 1

このエンドポイントですべてのユーザーを取得できませんでした。理由を教えてください。

少しハック的ですが、私の環境では機能する別の解決策があります:

/admin/users/list/active.json?show_emails=true&page=${page}
「いいね!」 1

“active” の代わりに “new” フラグを使用すると、すべてのユーザーを取得できます。ソート順を「作成日時昇順」に設定すれば、最も古いユーザーから新しいユーザーまで順に表示されます。ただし、ユーザー数が非常に多い場合、一度にすべてのユーザーを取得するリクエストは大きくなりすぎる可能性があるため、依然としてページネーションを使用してユーザーを取得する必要があります。

/admin/users/list/new?asc=true&order=created&page=0
「いいね!」 1

参考までに:

    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']}")
「いいね!」 6