# Use Environment variables inside of GraphQL variables

**URL:** <https://community.postman.com/t/use-environment-variables-inside-of-graphql-variables/8992>\
**Category:** Help Hub\
**Tags:** environments, graphql\
**Created:** [November 13, 2019, 7:29pm UTC](https://community.postman.com/t/use-environment-variables-inside-of-graphql-variables/8992 "2019-11-13T19:29:28Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![imageekgirl](https://avatars.discourse-cdn.com/v4/letter/i/838e76/32.png) [@imageekgirl](https://community.postman.com/u/imageekgirl)\
**Post date:** [January 20, 2021, 1:56am UTC](https://community.postman.com/t/use-environment-variables-inside-of-graphql-variables/8992/21 "2021-01-20T01:56:32Z")

</div>

This is the structure of the query (when it works); there are other fields one can query for beyond name and email, but my problem is getting the ID I’m querying on into the variables correctly:

```
query {
   
  SERVICENAME {
   getRecord(ReferenceID: "actual_string_value_in_quotes",
    ) {
     
        LastName
        FirstName
        Email    
                        }
                       }
            }
```

---

<div class="post-metadata">

**Author:** ![imageekgirl](https://avatars.discourse-cdn.com/v4/letter/i/838e76/32.png) [@imageekgirl](https://community.postman.com/u/imageekgirl)\
**Post date:** [January 20, 2021, 2:00am UTC](https://community.postman.com/t/use-environment-variables-inside-of-graphql-variables/8992/22 "2021-01-20T02:00:11Z")

</div>

When you click on query (in our schema docs), you select a service (in this case, shown as SERVICENAME), and then the type implements queries on different fields, including the getRecord by the ID shown above.

Does that make it more clear?

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [January 20, 2021, 4:46am UTC](https://community.postman.com/t/use-environment-variables-inside-of-graphql-variables/8992/23 "2021-01-20T04:46:43Z")

</div>

Hi there,

Maybe something like below might work?

```auto
query ($recruitmentID: String) {
   
  SERVICENAME {
   getRecord(ReferenceID: $recruitmentID,
    ) {
     
        LastName
        FirstName
        Email    
                

```

You can define `recruitmentID` as:

```auto
{
   "recruitmentID": "{{recruitmentID}}"
}

```

where `{{recruitmentID}}` is an environmental variable.

---

<div class="post-metadata">

**Author:** ![imageekgirl](https://avatars.discourse-cdn.com/v4/letter/i/838e76/32.png) [@imageekgirl](https://community.postman.com/u/imageekgirl)\
**Post date:** [January 20, 2021, 3:21pm UTC](https://community.postman.com/t/use-environment-variables-inside-of-graphql-variables/8992/24 "2021-01-20T15:21:07Z")

</div>

I tried the above and got the error message below; without an exclamation point after String, the error just listed the same with “String” instead.

```
` "message": "Variable \"$recruitmentID\" of type \"String!\" used in position expecting type \"ID!\"."`

```

Based on this error message, I changed String to ID and to ID! to no avail.

Using ID! resulted in

```
  "SERVICENAME": {
            "getRecord": null
        }

```

while using ID! as the first error message seemed to imply I should resulted in the error message of

`"message": "Variable \"$recruitmentID\" of type \"ID\" used in position expecting type \"ID!\".`

It seems like setting the type of ID! at least results in my objective being understood since it returns a null as opposed to an error, so it seems that has gotten us a little closer.

I wondered if having the two variables (environment and graphql) the same value was causing problems, but editing that did not change the null either.

It looks like what was suggested is what was shown in this video. [Sending GraphQL Queries in Postman - YouTube](https://www.youtube.com/watch?v=GLdcIXjkb7k) as well as the one from the Postman team.

Based on their docs, it looks like the right approach? [https://learning.postman.com/docs/sending-requests/supported-api-frameworks/graphql/](https://learning.postman.com/docs/sending-requests/supported-api-frameworks/graphql/)  
I’m not sure what else I need to do to get a logical result.

---

<div class="post-metadata">

**Author:** ![imageekgirl](https://avatars.discourse-cdn.com/v4/letter/i/838e76/32.png) [@imageekgirl](https://community.postman.com/u/imageekgirl)\
**Post date:** [January 20, 2021, 9:41pm UTC](https://community.postman.com/t/use-environment-variables-inside-of-graphql-variables/8992/25 "2021-01-20T21:41:04Z")

</div>

My last attempt (a sanity check of sorts) was to replace the Postman variable in the GraphQL variable with the actual value of the ID that worked.

Using that, my query returned the expected results.

So it seems like the format of my query is not the problem at this point, but in trying to use the environment variable saved as a GraphQL variable, something goes awry.

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [January 21, 2021, 12:14am UTC](https://community.postman.com/t/use-environment-variables-inside-of-graphql-variables/8992/26 "2021-01-21T00:14:53Z")

</div>

Hey @imageekgirl! Thanks for getting back 👋

I can see you are no longer seeing an error but getting “null” back - this implies that the value passed to `$recruitmentID` at least satisfies the schema but there is no matching result.

Can you share a screenshot showing the environment - I wonder if the variable is set correctly 🙂

---

<div class="post-metadata">

**Author:** ![imageekgirl](https://avatars.discourse-cdn.com/v4/letter/i/838e76/32.png) [@imageekgirl](https://community.postman.com/u/imageekgirl)\
**Post date:** [January 21, 2021, 12:22am UTC](https://community.postman.com/t/use-environment-variables-inside-of-graphql-variables/8992/27 "2021-01-21T00:22:41Z")

</div>

I think your question above led me to what was wrong with it.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/e/b/eb145d61a24a3beb628511b3d11be090a410d18c.png)  
In the example above of the environment variable itself, you can see there is an initial value and a current value.  
The same is true for the auth token; I just update the current value each day or so when working on this (and that is why it’s a tiny screenshot, as I didn’t want to show that).  
The recruitmentID had an initial value, but it did not persist to the current value column as you can see the environment variable does in this screenshot.  
It looks like when I copy and paste the ID so it’s in both the initial and current value fields for the {{recruitmentID}}, it works. The variables are where you suggested, and I’m getting the expected response body.  
Yes, I’m totally 🤦🏻‍♀️ here . . .

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [January 21, 2021, 12:46am UTC](https://community.postman.com/t/use-environment-variables-inside-of-graphql-variables/8992/28 "2021-01-21T00:46:32Z")

</div>

That’s awesome! Glad to hear the issue was resolved 🎉

---

<div class="post-metadata">

**Author:** ![imageekgirl](https://avatars.discourse-cdn.com/v4/letter/i/838e76/32.png) [@imageekgirl](https://community.postman.com/u/imageekgirl)\
**Post date:** [January 21, 2021, 1:16am UTC](https://community.postman.com/t/use-environment-variables-inside-of-graphql-variables/8992/29 "2021-01-21T01:16:10Z")

</div>

THANK YOU a million for helping me with this! 😃

[Previous page](https://community.postman.com/t/use-environment-variables-inside-of-graphql-variables/8992.md?page=1)
