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

**URL:** https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261
**Category:** Development
**Tags:** rest-api
**Created:** [21 Janeiro , 2015 09:34 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261 "2015-01-21T09:34:11Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![dirkcuys](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dirkcuys/32/106643_2.png) [@dirkcuys](https://meta.discourse.org/u/dirkcuys)
#### Post date: [21 Janeiro , 2015 09:34 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/1 "2015-01-21T09:34:11Z")

</div>

I see that I can get a list of users using the API using [http://discourse.example.net/admin/users.json](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.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [21 Janeiro , 2015 09:37 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/2 "2015-01-21T09:37:09Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dirkcuys](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dirkcuys/32/106643_2.png) [@dirkcuys](https://meta.discourse.org/u/dirkcuys)
#### Post date: [21 Janeiro , 2015 10:55 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/3 "2015-01-21T10:55:02Z")

</div>

sad panda indeed ☹ 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?

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [21 Janeiro , 2015 10:55 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/4 "2015-01-21T10:55:43Z")

</div>

> [@dirkcuys](#):
>
> Any idea if paging for users is wanted by anyone else

Yes 😄

> [@dirkcuys](#):
>
> if it is something that may be implemented at some stage?

No idea.

---

<div class="post-metadata">

### Author: ![downey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/downey/32/166878_2.png) [@downey](https://meta.discourse.org/u/downey)
#### Post date: [1 Abril , 2015 16:41 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/5 "2015-04-01T16:41:04Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![neuhausneuhaus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neuhausneuhaus/32/51550_2.png) [@neuhausneuhaus](https://meta.discourse.org/u/neuhausneuhaus)
#### Post date: [3 Fevereiro , 2016 17:51 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/6 "2016-02-03T17:51:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [4 Fevereiro , 2016 08:57 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/7 "2016-02-04T08:57:58Z")

</div>

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

> [@How to programmatically log out lots of users](https://meta.discourse.org/t/how-to-programmatically-log-out-lots-of-users/37611/15):
>
> As an alternative, here is a bit of JavaScript for node.js that iterates over a list of user ids and logs them out using the API: var logoutUsers = function (ids, domain, apiKey, delay) { var nextIndex = 0; var errors = 0; var callNextUrl = function () { if (nextIndex \< ids.length) { var id = ids[nextIndex]; nextIndex++; console.log("logging out " + id); var req = https.request({ hostname: domain, …

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [4 Fevereiro , 2016 13:26 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/8 "2016-02-04T13:26:00Z")

</div>

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:

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

```

---

<div class="post-metadata">

### Author: ![neuhausneuhaus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neuhausneuhaus/32/51550_2.png) [@neuhausneuhaus](https://meta.discourse.org/u/neuhausneuhaus)
#### Post date: [25 Fevereiro , 2016 17:47 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/9 "2016-02-25T17:47:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [6 Maio , 2016 20:56 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/10 "2016-05-06T20:56:02Z")

</div>

> [@DeanMarkTaylor](#):
>
> You’ll have to iterate over the following groups:
> 
> - trust\_level\_0
> - …
> - trust\_level\_4
> 
> But they do support both limit and offset parameters:
> 
> `/groups/trust_level_0/members.json?limit=50&offset=50`

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

> [@downey](#):
>
> It should only be necessary to do this for trust\_level\_0 since it includes all users in “higher” trust levels.

---

<div class="post-metadata">

### Author: ![jackzampolin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jackzampolin/32/121017_2.png) [@jackzampolin](https://meta.discourse.org/u/jackzampolin)
#### Post date: [27 Março , 2017 17:47 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/11 "2017-03-27T17:47:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [27 Março , 2017 18:07 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/12 "2017-03-27T18:07:20Z")

</div>

> [@jackzampolin](#):
>
> 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`.

---

<div class="post-metadata">

### Author: ![ryancey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryancey/32/99309_2.png) [@ryancey](https://meta.discourse.org/u/ryancey)
#### Post date: [11 Abril , 2019 16:28 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/13 "2019-04-11T16:28:47Z")

</div>

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](https://meta.discourse.org/t/data-explorer-plugin/32566) 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](https://github.com/discourse/discourse-oauth2-basic).

---

<div class="post-metadata">

### Author: ![abk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/abk/32/207505_2.png) [@abk](https://meta.discourse.org/u/abk)
#### Post date: [15 Fevereiro , 2021 20:55 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/14 "2021-02-15T20:55:57Z")

</div>

Uma resposta breve e atualizada: uma lista paginada de usuários está disponível de duas formas:

1. [Lista pública de usuários](https://docs.discourse.org/#tag/Users/paths/~1directory_items.json/get) como uma “listagem de diretório”
2. [Lista de usuários por “flag”](https://docs.discourse.org/#tag/Users/paths/~1admin~1users~1list~1%7Bflag%7D.json/get) Onde o `{flag}` na URL deve ser substituído por um Enum

Abraços,  
ABK

---

<div class="post-metadata">

### Author: ![Fares\_Droubi1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fares_droubi1/32/193803_2.png) [@Fares\_Droubi1](https://meta.discourse.org/u/Fares_Droubi1)
#### Post date: [12 Agosto , 2021 09:10 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/15 "2021-08-12T09:10:32Z")

</div>

Olá,

> [Lista de usuários por “flag”](https://docs.discourse.org/#tag/Users/paths/~1admin~1users~1list~1%7Bflag%7D.json/get)

Existe uma flag para obter todos os usuários? Algo como https://{defaultHost}/admin/users/list/all.json

---

<div class="post-metadata">

### Author: ![Fares\_Droubi1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fares_droubi1/32/193803_2.png) [@Fares\_Droubi1](https://meta.discourse.org/u/Fares_Droubi1)
#### Post date: [12 Agosto , 2021 13:48 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/16 "2021-08-12T13:48:18Z")

</div>

Não consegui buscar todos os usuários usando este endpoint. Alguma explicação?

---

<div class="post-metadata">

### Author: ![Fares\_Droubi1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fares_droubi1/32/193803_2.png) [@Fares\_Droubi1](https://meta.discourse.org/u/Fares_Droubi1)
#### Post date: [12 Agosto , 2021 15:10 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/17 "2021-08-12T15:10:48Z")

</div>

Outra solução um pouco hacky, mas que funciona para mim:

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

```

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [12 Agosto , 2021 19:20 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/18 "2021-08-12T19:20:03Z")

</div>

> [@Fares\_Droubi1](#):
>
> existe uma flag para obter todos os usuários?

Usar a flag “new” em vez de “active” deve fornecer TODOS os usuários. Basta ordenar por criação em ordem crescente e você obterá todos os usuários, do mais antigo ao mais recente. Ainda será necessário usar paginação para buscar todos os usuários; caso contrário, a solicitação pode ficar excessivamente grande se houver muitos usuários.

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

```

---

<div class="post-metadata">

### Author: ![mattdm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattdm/32/216484_2.png) [@mattdm](https://meta.discourse.org/u/mattdm)
#### Post date: [24 Dezembro , 2021 18:59 UTC](https://meta.discourse.org/t/how-do-i-get-a-list-of-all-users-from-the-api/24261/19 "2021-12-24T18:59:51Z")

</div>

Apenas para constar:

```python
    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']}")

```
