# Retrieving user information via REST API

**URL:** https://meta.discourse.org/t/retrieving-user-information-via-rest-api/90425
**Category:** Development
**Created:** [June 21, 2018, 9:48pm UTC](https://meta.discourse.org/t/retrieving-user-information-via-rest-api/90425 "2018-06-21T21:48:35Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![sarahann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sarahann/32/96703_2.png) [@sarahann](https://meta.discourse.org/u/sarahann)
#### Post date: [June 21, 2018, 9:48pm UTC](https://meta.discourse.org/t/retrieving-user-information-via-rest-api/90425/1 "2018-06-21T21:48:35Z")

</div>

Hello!

I have been looking for some specific user data. The users flagged data:

- number\_of\_flagged\_posts
- number\_of\_suspensions
- warnings\_received\_count

I found that this information is part of the user class

> <https://github.com/discourse/discourse/blob/bc52bdfa1280ba08e6fb1931c26e18aa7fee9f7f/app/models/user.rb>

but is not part of the ‘user’ that the REST API returns

> **[Discourse API Docs](https://docs.discourse.org/#tag/Tags%2Fpaths%2F~1tags~1%7Btag%7D%2Fget)**

> **[Discourse API Docs](https://docs.discourse.org/#tag/Users%2Fpaths%2F~1admin~1users~1list~1%7Bflag%7D.json%2Fget)**

I am wondering how I can get the user’s

- number\_of\_flagged\_posts
- number\_of\_suspensions
- warnings\_received\_count

through the REST API. And if it’s not possible, then is a plugin REST API that surfaces this information the enxt best option?

---

<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: [June 21, 2018, 10:44pm UTC](https://meta.discourse.org/t/retrieving-user-information-via-rest-api/90425/2 "2018-06-21T22:44:06Z")

</div>

Apparently the admin user route isn’t documented in the API Docs. I’ll make sure that route is added.

If you GET `/admin/users/{id}.json` it will return these fields which are close to what you are after:

```plaintext
flags_given_count
flags_received_count
warnings_received_count
suspended (boolean)

```

> [@sarahann](#):
>
> And if it’s not possible, then is a plugin REST API that surfaces this information the enxt best option?

I would start with the [Discourse Data Explorer](https://meta.discourse.org/t/data-explorer-plugin/32566) where you can create a saved query that you can send an API call to and pass it a user id to return exactly what you are after. But yes, creating a plugin that creates a new route to expose those fields is also an option.

---

<div class="post-metadata">

### Author: ![sarahann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sarahann/32/96703_2.png) [@sarahann](https://meta.discourse.org/u/sarahann)
#### Post date: [June 21, 2018, 10:49pm UTC](https://meta.discourse.org/t/retrieving-user-information-via-rest-api/90425/3 "2018-06-21T22:49:59Z")

</div>

> [@blake](#):
>
> /admin/users/{id}.json

AHH THANK YOU! This is what I was looking for! You’re awesome 🙂

---

<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: [June 23, 2018, 5:42pm UTC](https://meta.discourse.org/t/retrieving-user-information-via-rest-api/90425/4 "2018-06-23T17:42:23Z")

</div>

> [@blake](#):
>
> Apparently the admin user route isn’t documented in the API Docs. I’ll make sure that route is added.

I just added the GET [`/admin/users/{id}.json`](https://docs.discourse.org/#tag/Users%2Fpaths%2F~1admin~1users~1%7Bid%7D.json%2Fget) route to the [api docs](https://docs.discourse.org/).

---

<div class="post-metadata">

### Author: ![sarahann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sarahann/32/96703_2.png) [@sarahann](https://meta.discourse.org/u/sarahann)
#### Post date: [July 4, 2018, 8:15pm UTC](https://meta.discourse.org/t/retrieving-user-information-via-rest-api/90425/5 "2018-07-04T20:15:52Z")

</div>

To add to this, I also noticed that the **silence** endpoint isn’t visible in the API docs as well. I found it by taking a guess 😛

Endpoint:  
PUT /admin/users/{id}/silence

---

<div class="post-metadata">

### Author: ![sarahann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sarahann/32/96703_2.png) [@sarahann](https://meta.discourse.org/u/sarahann)
#### Post date: [July 5, 2018, 12:38am UTC](https://meta.discourse.org/t/retrieving-user-information-via-rest-api/90425/6 "2018-07-05T00:38:52Z")

</div>

Hmm I have also noticed a few differences between the two endpoints (in case @blake you were going to add the silence user to the API docs)

| suspend | silence | differences |
| --- | --- | --- |
| PUT /admin/users/{id}/suspend | PUT /admin/users/{id}/silence | endpoints |
| suspend\_until | silenced\_till | request body |
| Yes | No | Update while silenced /suspended |

The last column in the table is causing me some trouble at the moment. I am trying to silence a user programmatically, but if they have already been silenced before, and I make a new silencing request with a later silenced\_till date the date doesn’t get updated.

Almost as if the endpoint is saying “do nothing if the user is already silenced”

The suspend endpoint doesn’t behave like this. Rather it updates the suspend\_until time.

Any advice?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [July 5, 2018, 1:54am UTC](https://meta.discourse.org/t/retrieving-user-information-via-rest-api/90425/7 "2018-07-05T01:54:29Z")

</div>

> [@sarahann](#):
>
> Almost as if the endpoint is saying “do nothing if the user is already silenced”

It is. You can see where it happens here: [discourse/app/services/user\_silencer.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/app/services/user_silencer.rb#L21)

It’s possible to update the `silenced_till` parameter directly on the user, but there’s no API endpoint for that, so doing it that way would require a plugin.
