# API - Username instead of id on \_by/\_mby

**URL:** <https://discourse.getcockpit.com/t/api-username-instead-of-id-on-by-mby/2063>\
**Category:** Support\
**Created:** [September 4, 2021, 6:38pm UTC](https://discourse.getcockpit.com/t/api-username-instead-of-id-on-by-mby/2063 "2021-09-04T18:38:58Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![ronaldaug](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/ronaldaug/32/260_2.png) [@ronaldaug](https://discourse.getcockpit.com/u/ronaldaug)\
**Post date:** [September 5, 2021, 8:05am UTC](https://discourse.getcockpit.com/t/api-username-instead-of-id-on-by-mby/2063/4 "2021-09-05T08:05:56Z")

</div>

> [@linhous](#):
>
> But with AccountLink, even using “Populate=1”, it doesn’t show the username or any other field, it just returns the ID anyway ☹

My bad, I should have mentioned that `populate` only work with `collectionLink`.

And you can’t retrieve accountLink data with collection data at the same time. Maybe it could be the security reason.

### Option 1

Fire one more API request with account ID to get the user data

### Option 2

Ref answer by raffaelj: [How to refer to another Collections or "Accounts" - #7 by raffaelj](https://discourse.getcockpit.com/t/how-to-refer-to-another-collections-or-accounts/324/7)

- create `config` directory in the root folder, under that directory create `bootstrap.php` file. Add the below codes. Make sure you don’t expose account sensitive data.

> Replace “collection\_name” with your actual collection name.

```auto
<?php

// This will append "author" object into API response. 

if (COCKPIT_API_REQUEST) {

    $app->on('collections.find.after.collection_name', function($name, &$entries) {

        function getSomeFields($array){
            $author_name = !empty($array['name'])?$array['name']:$array['user'];

            // Only return 2 fields "name" and "_id"
            return [
            "name" => $author_name,
            "_id" => $array['_id']
           ];
        }

        foreach ($entries as &$entry) {

                $account = $this->storage->findOne('cockpit/accounts', ['_id' => $entry['_by']]);
                $account = !empty($account)?getSomeFields($account):[];

                // You can rename "author" as you want                
                $entry['author'] = $account;

        }

    });

}

```

---

_[View the full topic](https://discourse.getcockpit.com/t/api-username-instead-of-id-on-by-mby/2063)._
