# Return only specific fields from the API GET response

**URL:** https://meta.discourse.org/t/return-only-specific-fields-from-the-api-get-response/244695
**Category:** Development
**Tags:** rest-api
**Created:** [November 7, 2022, 6:01pm UTC](https://meta.discourse.org/t/return-only-specific-fields-from-the-api-get-response/244695 "2022-11-07T18:01:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![gassim](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gassim/32/220910_2.png) [@gassim](https://meta.discourse.org/u/gassim)
#### Post date: [November 7, 2022, 6:01pm UTC](https://meta.discourse.org/t/return-only-specific-fields-from-the-api-get-response/244695/1 "2022-11-07T18:01:16Z")

</div>

Continuing the discussion from [Discourse API Documentation](https://meta.discourse.org/t/discourse-api-documentation/22706):

Hi

I couldn’t find an answer to this, please. Does anyone know if it’s possible to specify that the Discourse API response to a GET request returns only the requested field?

For example, the GET request to List group members (https://{defaultHost}/groups/{id}/members.json) returns:

> ```plaintext
> {
> "members": [
> {
> "id": 0,
> "username": "string",
> "name": "string",
> "avatar_template": "string",
> "title": "string",
> "last_posted_at": "string",
> "last_seen_at": "string",
> "added_at": "string",
> "timezone": "string"
> }
> ],
> "owners": [
> {
> "id": 0,
> "username": "string",
> "name": "string",
> "avatar_template": "string",
> "title": "string",
> "last_posted_at": "string",
> "last_seen_at": "string",
> "added_at": "string",
> "timezone": "string"
> }
> ],
> "meta": {
> "total": 0,
> "limit": 0,
> "offset": 0
> }
> }
> 
> ```

Is there a way to make the response return only a specific field/? For example, to return only the member’s usernames?

```plaintext
{
  "members": [
    {
       "username": "string"
    }
  ]
}

```

I know it’s possible to retrieve the whole response and then use coding to filter the JSON and the arrays in order to get a specific value; however, I want the request to return the specific value instead. Is this possible?

Thank you!

---

<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: [November 7, 2022, 7:01pm UTC](https://meta.discourse.org/t/return-only-specific-fields-from-the-api-get-response/244695/2 "2022-11-07T19:01:46Z")

</div>

> [@gassim](#):
>
> Does anyone know if it’s possible to specify that the Discourse API response to a GET request returns only the requested field?

Great question, but no this is not an option. There is not anything in the core app that is listening for params to filter by.

I think you will be best off just filtering out the results either with a tool like `jq` on the command line or using whatever programming language you are using to make the api requests.

If this is indeed a must have requirement two options do exist though. You could use the [data explorer](https://meta.discourse.org/t/32566?silent=true) plugin with a query that returns only the data you need and then make an api request to that query. Another alternative would be to create a custom plugin that you create a new route and controller for that returns only the data you need.

---

<div class="post-metadata">

### Author: ![gassim](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gassim/32/220910_2.png) [@gassim](https://meta.discourse.org/u/gassim)
#### Post date: [November 7, 2022, 7:04pm UTC](https://meta.discourse.org/t/return-only-specific-fields-from-the-api-get-response/244695/3 "2022-11-07T19:04:14Z")

</div>

> [@blake](#):
>
> You could use the [data explorer](https://meta.discourse.org/t/32566?silent=true) plugin with a query that returns only the data you need and then make an api request to that query.

Amazing! I think this will help a lot. 🙏 Thank you so much!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 7, 2022, 7:04pm UTC](https://meta.discourse.org/t/return-only-specific-fields-from-the-api-get-response/244695/4 "2022-12-07T19:04:48Z")

</div>

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