# How to use the App Environment SDK in functions?

**URL:** <https://community.dynatrace.com/t/how-to-use-the-app-environment-sdk-in-functions/39443>\
**Category:** Developer Q&A Forum\
**Tags:** coding-assistance\
**Created:** [April 25, 2023, 10:40am UTC](https://community.dynatrace.com/t/how-to-use-the-app-environment-sdk-in-functions/39443 "2023-04-25T10:40:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas\_c](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/thomas_c/32/17633_2.png) [@thomas\_c](https://community.dynatrace.com/u/thomas_c)\
**Post date:** [April 25, 2023, 10:40am UTC](https://community.dynatrace.com/t/how-to-use-the-app-environment-sdk-in-functions/39443/1 "2023-04-25T10:40:03Z")

</div>

Hi Team,

I need to retrieve and use the environment’s URL in a Dashboard/Notebook function.

The [docs](https://developer.dynatrace.com/reference/sdks/app-environment/#getenvironmenturl) seems lacking the info on which SDK to import. I tried the following but get an error:

 ![thomas_c_0-1682419101752.png](https://global.discourse-cdn.com/dynatrace/original/3X/b/c/bc634fad36473d825dfb0f6400dcb3a512b5a0e9.png)

Could you please guide me on using that SDK?

Thanks,

Thomas

---

<div class="post-metadata">

**Author:** ![stefan\_eggersto](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/stefan_eggersto/32/34114_2.png) [@stefan\_eggersto](https://community.dynatrace.com/u/stefan_eggersto)\
**Post date:** [April 25, 2023, 11:04am UTC](https://community.dynatrace.com/t/how-to-use-the-app-environment-sdk-in-functions/39443/2 "2023-04-25T11:04:09Z")

</div>

Hi Thomas,

`@dynatrace-sdk/app-environment` can only be used in apps and is not available for ad-hoc functions.

As an alternative, you can use `globalThis.environmentUrl` to access the environment URL.

---

<div class="post-metadata">

**Author:** ![thomas\_c](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/thomas_c/32/17633_2.png) [@thomas\_c](https://community.dynatrace.com/u/thomas_c)\
**Post date:** [April 26, 2023, 4:21pm UTC](https://community.dynatrace.com/t/how-to-use-the-app-environment-sdk-in-functions/39443/3 "2023-04-26T16:21:32Z")

</div>

Thanks Stefan! That works great in ad-hoc functions too.

Just to close the loop, is there a way to use such globalThis properties in a dashboard’s markdown tile? Just like we can do via a dashboard variable.

---

<div class="post-metadata">

**Author:** ![MarwanC](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marwanc/32/34480_2.png) [@MarwanC](https://community.dynatrace.com/u/MarwanC)\
**Post date:** [June 26, 2025, 10:36am UTC](https://community.dynatrace.com/t/how-to-use-the-app-environment-sdk-in-functions/39443/4 "2025-06-26T10:36:28Z")

</div>

Can you kindly let me know how extract the incoming header and the body as I need to process those to do other stuff in the app function?&nbsp; can I use&nbsp;globalThis.? where is the documentation can be found of&nbsp;globalThis.x Thanks in advance for your support

---

<div class="post-metadata">

**Author:** ![MarwanC](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marwanc/32/34480_2.png) [@MarwanC](https://community.dynatrace.com/u/MarwanC)\
**Post date:** [June 26, 2025, 10:37am UTC](https://community.dynatrace.com/t/how-to-use-the-app-environment-sdk-in-functions/39443/5 "2025-06-26T10:37:13Z")

</div>

Dear Stefan, Can you kindly let me know how extract the incoming header and the body as I need to process those to do other stuff in the app function?&nbsp; can I use&nbsp;globalThis.? where is the documentation can be found of&nbsp;globalThis.x Thanks in advance for your support

---

<div class="post-metadata">

**Author:** ![MarwanC](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marwanc/32/34480_2.png) [@MarwanC](https://community.dynatrace.com/u/MarwanC)\
**Post date:** [June 26, 2025, 10:58am UTC](https://community.dynatrace.com/t/how-to-use-the-app-environment-sdk-in-functions/39443/6 "2025-06-26T10:58:29Z")

</div>

I also see that

globalThis.environmentUrl&nbsp; is marked as depricated and they advise to use this code, hope this is helpful to everyone:&nbsp;&nbsp;import { getEnvironmentId } from ‘@dynatrace-sdk/app-environment’;  
export default async function (payload: unknown = undefined) {&nbsp; // Get the current environment ID&nbsp; const environmentId = getEnvironmentId();&nbsp; return environmentId;}

---

<div class="post-metadata">

**Author:** ![MarwanC](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marwanc/32/34480_2.png) [@MarwanC](https://community.dynatrace.com/u/MarwanC)\
**Post date:** [June 26, 2025, 11:24am UTC](https://community.dynatrace.com/t/how-to-use-the-app-environment-sdk-in-functions/39443/7 "2025-06-26T11:24:57Z")

</div>

import { getEnvironmentUrl } from ‘@dynatrace-sdk/app-environment’;  
export default async function (payload: unknown = undefined) {&nbsp; // Get the current environment URL&nbsp; const environmentUrl = getEnvironmentUrl();&nbsp; return environmentUrl;}If the URL is required use the above
