# Setting Ocp-Apim-Subscription-Key in GraphQL client interface

**URL:** <https://community.postman.com/t/setting-ocp-apim-subscription-key-in-graphql-client-interface/83625>\
**Category:** Help Hub\
**Tags:** scripts, authentication\
**Created:** [August 15, 2025, 4:40pm UTC](https://community.postman.com/t/setting-ocp-apim-subscription-key-in-graphql-client-interface/83625 "2025-08-15T16:40:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidanwhitehall-dfs](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@aidanwhitehall-dfs](https://community.postman.com/u/aidanwhitehall-dfs)\
**Post date:** [August 15, 2025, 4:40pm UTC](https://community.postman.com/t/setting-ocp-apim-subscription-key-in-graphql-client-interface/83625/1 "2025-08-15T16:40:54Z")

</div>

Should it be possible to set the `Ocp-Apim-Subscription-Key` header in a **Before query** script in the GraphQL client interface?

The short script below works fine as a **pre-request** script in a GraphQL query in an HTTP request, but the same code in a **Before query** script in the GraphQL client interface produces a **401 Unauthorized: Access denied due to missing subscription key**.

Manually adding an `Ocp-Apim-Subscription-Key` header with a string literal value works fine (in the GraphQL client interface), but then doesn’t allow for easy switching between environments (where the key differs between environments).

Thanks for any pointers!

```auto
pm.request.headers.add({
    key: "Ocp-Apim-Subscription-Key",
    value: pm.environment.get("ocpApimSubscriptionKey")
});

```

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [August 16, 2025, 12:09pm UTC](https://community.postman.com/t/setting-ocp-apim-subscription-key-in-graphql-client-interface/83625/2 "2025-08-16T12:09:23Z")

</div>

When you manually add the header, you can just set the value to the environment variable.

> {{ocpApimSubscriptionKey}}

---

<div class="post-metadata">

**Author:** ![aidanwhitehall-dfs](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@aidanwhitehall-dfs](https://community.postman.com/u/aidanwhitehall-dfs)\
**Post date:** [August 16, 2025, 1:49pm UTC](https://community.postman.com/t/setting-ocp-apim-subscription-key-in-graphql-client-interface/83625/3 "2025-08-16T13:49:59Z")

</div>

Yes, of course you can… 🤦‍♂️

Thank you, Mike! 🙏
