# How to get the visitor's custom fields information using Node JS SDK

**URL:** <https://forums.rocket.chat/t/how-to-get-the-visitors-custom-fields-information-using-node-js-sdk/798>\
**Category:** Community Support\
**Created:** [May 23, 2018, 9:54am UTC](https://forums.rocket.chat/t/how-to-get-the-visitors-custom-fields-information-using-node-js-sdk/798 "2018-05-23T09:54:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gurmeet.khanchi](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@gurmeet.khanchi](https://forums.rocket.chat/u/gurmeet.khanchi)\
**Post date:** [May 23, 2018, 9:54am UTC](https://forums.rocket.chat/t/how-to-get-the-visitors-custom-fields-information-using-node-js-sdk/798/1 "2018-05-23T09:54:24Z")

</div>

Hi,

I have added some custom fields in the Live chat and sending the data from the customer Widget. I have created a bot using Node JS SDK. But I don’t know how to get the custom fields visitor information. I have gone through the documentation but no luck.

The information is not there in the message object. The user object is there but only limited info is there:  
u: { \_id: ‘XePzirgYNBs9XSt5L’, username: ‘guest-29’, name: null }

---

<div class="post-metadata">

**Author:** ![tim.kinnane](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/tim.kinnane/32/71_2.png) [@tim.kinnane](https://forums.rocket.chat/u/tim.kinnane)\
**Post date:** [May 24, 2018, 1:03pm UTC](https://forums.rocket.chat/t/how-to-get-the-visitors-custom-fields-information-using-node-js-sdk/798/2 "2018-05-24T13:03:27Z")

</div>

Yes, there’s not much user information in the meta from the message stream, but the SDK also includes a module for using the API. So once you’ve got the user ID, you can make a follow up request.

Docs for the endpoint…  
[https://rocket.chat/docs/developer-guides/rest-api/users/info/](https://rocket.chat/docs/developer-guides/rest-api/users/info/)

Basic details on usage…

> **[RocketChat/Rocket.Chat.js.SDK](https://github.com/RocketChat/Rocket.Chat.js.SDK#apigetendpoint-data-auth-ignore)**
>
> Utility for apps and bots to interact with Rocket.Chat via DDP and/or API - RocketChat/Rocket.Chat.js.SDK

Test file shows it in action…

> <https://github.com/RocketChat/Rocket.Chat.js.SDK/blob/master/src/lib/api.spec.ts#L62-L69>

---

<div class="post-metadata">

**Author:** ![gurmeet.khanchi](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@gurmeet.khanchi](https://forums.rocket.chat/u/gurmeet.khanchi)\
**Post date:** [May 25, 2018, 5:19am UTC](https://forums.rocket.chat/t/how-to-get-the-visitors-custom-fields-information-using-node-js-sdk/798/3 "2018-05-25T05:19:16Z")

</div>

Thanks Tim,

Actually I tried the users api but for the guest user it’s giving Invalid user error. From the widget I am sending some custom fields like  
RocketChat(function() {  
this.setDepartment(‘Bot’);  
this.setCustomField(‘accountId’, ‘7’);  
});

I want to access these fields in my code where I am using Rocket.Chat.js.SDK.

But I didn’t find any way to get this information. I am not sure if this will be a part of User object or some other Object. In the message it’s not present. I am able to see it in the Live Chat agent’s visitor Info(the scope of theese fields is set to Vistors).

---

<div class="post-metadata">

**Author:** ![tim.kinnane](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/tim.kinnane/32/71_2.png) [@tim.kinnane](https://forums.rocket.chat/u/tim.kinnane)\
**Post date:** [June 12, 2018, 6:23am UTC](https://forums.rocket.chat/t/how-to-get-the-visitors-custom-fields-information-using-node-js-sdk/798/4 "2018-06-12T06:23:19Z")

</div>

I’ve added some snippets to demonstrate similar interactions via the SDK, in Hubot. You might find something there to follow: [https://rocket.chat/hubot-rocketchat/snippets](https://rocket.chat/hubot-rocketchat/snippets) - specifically “Use API to check if role exists on given user” - The other thing you might need is to make sure the bot has `view-full-other-user-info` permission. Since you’re talking about getting custom user data, it won’t be included in the basic user data response.

---

<div class="post-metadata">

**Author:** ![gurmeet.khanchi](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@gurmeet.khanchi](https://forums.rocket.chat/u/gurmeet.khanchi)\
**Post date:** [June 19, 2018, 5:27am UTC](https://forums.rocket.chat/t/how-to-get-the-visitors-custom-fields-information-using-node-js-sdk/798/5 "2018-06-19T05:27:32Z")

</div>

Hi Tim,

I am able to get the custom field defined in the widget:

```
   RocketChat(function() {
       this.setCustomField('userToken', 'userToken');  
   });

```

I am using NodeJS SDK. There are two methods:

1. var cstmFieldsData = {  
roomId: message.rid,  
departmentId: DEPARTMENT\_ID  
}  
var cstmFields = driver.callMethod(‘livechat:getCustomFields’, cstmFieldsData);

2. var roomsData = driver.callMethod(‘rooms/get’, []);

Can someone please investigate this issue?
