# Help to Get the Sessions ID

**URL:** <https://forum.inductiveautomation.com/t/help-to-get-the-sessions-id/66716>\
**Category:** Module Development\
**Tags:** perspective\
**Created:** [November 19, 2022, 8:53pm UTC](https://forum.inductiveautomation.com/t/help-to-get-the-sessions-id/66716 "2022-11-19T20:53:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_mohamed](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahmed_mohamed/32/53025_2.png) [@Ahmed\_mohamed](https://forum.inductiveautomation.com/u/Ahmed_mohamed)\
**Post date:** [November 19, 2022, 8:53pm UTC](https://forum.inductiveautomation.com/t/help-to-get-the-sessions-id/66716/1 "2022-11-19T20:53:52Z")

</div>

Hi everyone,  
I have 2 questions  
**First one:**  
I need to get all Sessions IDs to send msg to them using the message handler, there are any way to do that?  
**Second one:**  
if i try to get The current SessionId to pass the message directly with this code:

> String SessionId = InternalSession.SESSION.get().getSession().getSessionId().toString();

I got this error:

```auto
java.lang.NullPointerException: null

```

I think I had misunderstood using **InternalSession** , should I import its package and use it directly or declare it in specific Scope  
Thanks in advanced

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 21, 2022, 8:56am UTC](https://forum.inductiveautomation.com/t/help-to-get-the-sessions-id/66716/2 "2022-11-21T08:56:55Z")

</div>

perspective or vision?

---

<div class="post-metadata">

**Author:** ![Ahmed\_mohamed](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahmed_mohamed/32/53025_2.png) [@Ahmed\_mohamed](https://forum.inductiveautomation.com/u/Ahmed_mohamed)\
**Post date:** [November 21, 2022, 9:04am UTC](https://forum.inductiveautomation.com/t/help-to-get-the-sessions-id/66716/3 "2022-11-21T09:04:57Z")

</div>

> [@victordcq](#):
>
> perspective

perspective

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 21, 2022, 9:30am UTC](https://forum.inductiveautomation.com/t/help-to-get-the-sessions-id/66716/4 "2022-11-21T09:30:23Z")

</div>

And you are trying to do this in a model (more specific the gateway delegate)?

Or just trying to get it through a (system) function so you can use it in an external lib?

I made a (system) function for that once like this.

You'll also need to register these functions in the gateway and designer

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/1/b146c5524135ed5e1f3ccf4fcdd696224c3ec583.png)

You can probably get all the sessionInfo's from here  
[com/inductiveautomation/ignition/common/script/builtin/SystemUtilities.html#getSessionInfo()](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.15/com/inductiveautomation/ignition/common/script/builtin/SystemUtilities.html#getSessionInfo())

---

<div class="post-metadata">

**Author:** ![Ahmed\_mohamed](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahmed_mohamed/32/53025_2.png) [@Ahmed\_mohamed](https://forum.inductiveautomation.com/u/Ahmed_mohamed)\
**Post date:** [November 21, 2022, 10:00am UTC](https://forum.inductiveautomation.com/t/help-to-get-the-sessions-id/66716/5 "2022-11-21T10:00:21Z")

</div>

Thanks, Victor,  
My fault that I didn't set Gatewaycontext,  
Thank you again ❤

---

<div class="post-metadata">

**Author:** ![Ivan\_H](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ivan_h/32/28186_2.png) [@Ivan\_H](https://forum.inductiveautomation.com/u/Ivan_H)\
**Post date:** [January 21, 2023, 9:42pm UTC](https://forum.inductiveautomation.com/t/help-to-get-the-sessions-id/66716/6 "2023-01-21T21:42:05Z")

</div>

Whay is the proper way to set the gatewayContext?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 21, 2023, 10:21pm UTC](https://forum.inductiveautomation.com/t/help-to-get-the-sessions-id/66716/7 "2023-01-21T22:21:10Z")

</div>

You capture it in your module's setup hook and save it in a field. I tend to use a private static field and matching getter so the rest of the module can obtain it via that static method.

---

<div class="post-metadata">

**Author:** ![Ivan\_H](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ivan_h/32/28186_2.png) [@Ivan\_H](https://forum.inductiveautomation.com/u/Ivan_H)\
**Post date:** [January 23, 2023, 10:34pm UTC](https://forum.inductiveautomation.com/t/help-to-get-the-sessions-id/66716/8 "2023-01-23T22:34:14Z")

</div>

Proper indeed, thanks @pturmel.
