# Accessing sender's custom fields inside ISlashCommand's executor

**URL:** <https://forums.rocket.chat/t/accessing-senders-custom-fields-inside-islashcommands-executor/9715>\
**Category:** Rocket.Chat Apps\
**Created:** [December 15, 2020, 10:34am UTC](https://forums.rocket.chat/t/accessing-senders-custom-fields-inside-islashcommands-executor/9715 "2020-12-15T10:34:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davide](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@davide](https://forums.rocket.chat/u/davide)\
**Post date:** [December 15, 2020, 10:34am UTC](https://forums.rocket.chat/t/accessing-senders-custom-fields-inside-islashcommands-executor/9715/1 "2020-12-15T10:34:48Z")

</div>

I have a simple text-type custom field I would like to access from inside a slash command.  
The field is defined in Rocket.Chat server’s settings:

```auto
{
	"Extension": {
		"type": "text",
		"required": false,
		"public": true,
        "private": false,
		"sendToIntegrations": true
	
	}
}

```

Custom fields’ values should be accessible (I think) via the `IUser.customFields?` optional dictionary, but it seems it is not filled with anything.

```auto
public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): Promise<void> {
        console.log(context.getSender());
        console.log(context.getSender().customFields?.['Extension']);
}

```

produces

```auto
rocketchat_1 | {
rocketchat_1 | id: '3Gg7KDwQiGeY9Yp2w',
rocketchat_1 | username: 'davide',
rocketchat_1 | emails: [{ address: 'admin@example.com', verified: false }],
rocketchat_1 | type: 'user',
rocketchat_1 | isEnabled: true,
rocketchat_1 | name: 'Davide',
rocketchat_1 | roles: ['admin'],
rocketchat_1 | status: 'online',
rocketchat_1 | statusConnection: 'online',
rocketchat_1 | utcOffset: 1,
rocketchat_1 | createdAt: 2020-12-07T11:05:51.516Z,
rocketchat_1 | updatedAt: 2020-12-15T10:10:26.918Z,
rocketchat_1 | lastLoginAt: 2020-12-15T09:51:42.335Z,
rocketchat_1 | appId: undefined
rocketchat_1 | }
rocketchat_1 | undefined

```

where no attribute `customFields` is present.  
Is this the right way to access custom fields?  
I am using the rocketchat/rocket.chat:latest Docker image to deploy the slash command.

---

<div class="post-metadata">

**Author:** ![donny](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@donny](https://forums.rocket.chat/u/donny)\
**Post date:** [March 9, 2021, 2:37pm UTC](https://forums.rocket.chat/t/accessing-senders-custom-fields-inside-islashcommands-executor/9715/2 "2021-03-09T14:37:54Z")

</div>

Hi, did you manage to fix the problem?

---

<div class="post-metadata">

**Author:** ![davide](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@davide](https://forums.rocket.chat/u/davide)\
**Post date:** [March 9, 2021, 6:13pm UTC](https://forums.rocket.chat/t/accessing-senders-custom-fields-inside-islashcommands-executor/9715/3 "2021-03-09T18:13:50Z")

</div>

Hi, thanks for reminding me of this.  
I ended up not needing this any more.  
However, you can access it through this REST call:  
[https://docs.rocket.chat/api/rest-api/methods/users/info](https://docs.rocket.chat/api/rest-api/methods/users/info)  
If the custom field `Extension` exists, the returned object will contain the field

```auto
{
    "user":
        //...
        "customFields": {
             "Extension": "blah"
        }
}

```

This call requires authentication, so you need to provide an authentication token in the headers of your request. Not sure if needed inside an app, but probably yes.  
This call returns the token provided you have username and password of a registered user:  
[https://docs.rocket.chat/api/rest-api/methods/authentication/login](https://docs.rocket.chat/api/rest-api/methods/authentication/login)

To make a REST call from a slashcommand, check  
[https://docs.rocket.chat/apps-development/recipes/making-http-requests](https://docs.rocket.chat/apps-development/recipes/making-http-requests)

Not sure how to add HTTP headers to a GET request, couldn’t find the docs right on the spot.  
I will update this answer as soon as I have some time to test some working example.

---

<div class="post-metadata">

**Author:** ![lev](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/lev/32/1979_2.png) [@lev](https://forums.rocket.chat/u/lev)\
**Post date:** [March 29, 2021, 1:52pm UTC](https://forums.rocket.chat/t/accessing-senders-custom-fields-inside-islashcommands-executor/9715/4 "2021-03-29T13:52:24Z")

</div>

Custom fields in applications are very useful. I was disappointed that there is no explicit way to get them.  
I’m currently looking for workarounds in the process.  
Have you made progress with this problem?

The room object has a field, but the user object does not. This looks like a bug.  
 ![image](https://us1.discourse-cdn.com/flex021/uploads/rocketchat/original/2X/9/926dfb7e7c4f3aab244ddc4b68fb1ba789c69684.png)

---

<div class="post-metadata">

**Author:** ![kierenevans](https://avatars.discourse-cdn.com/v4/letter/k/f07891/32.png) [@kierenevans](https://forums.rocket.chat/u/kierenevans)\
**Post date:** [July 29, 2021, 6:12pm UTC](https://forums.rocket.chat/t/accessing-senders-custom-fields-inside-islashcommands-executor/9715/5 "2021-07-29T18:12:28Z")

</div>

I think this will be fixed by [[FIX] Add missing custom fields to apps' users converter by cuonghuunguyen · Pull Request #21176 · RocketChat/Rocket.Chat · GitHub](https://github.com/RocketChat/Rocket.Chat/pull/21176)
