# URI encoding in pre-req

**URL:** <https://community.postman.com/t/uri-encoding-in-pre-req/41885>\
**Category:** Help Hub\
**Created:** [December 8, 2022, 3:50pm UTC](https://community.postman.com/t/uri-encoding-in-pre-req/41885 "2022-12-08T15:50:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradawk1](https://avatars.discourse-cdn.com/v4/letter/b/439d5e/32.png) [@bradawk1](https://community.postman.com/u/bradawk1)\
**Post date:** [December 8, 2022, 3:50pm UTC](https://community.postman.com/t/uri-encoding-in-pre-req/41885/1 "2022-12-08T15:50:39Z")

</div>

This curl works:

```auto
curl --insecure \
     --header "auth: ${sessionID}" \
     --header "X-API-Version: ${currentVersion}" \
     --request GET ${OneView}/rest/server-hardware?filter=%22%27serverName%27%20=%20%27my-host%27%22`

```

I defined SERVER with the FQDN in the environment. I’m trying to set a variable in the pre-req section to hold the encoded value. I tried:

```auto
var encoded = encodeURIComponent("'serverName' = '{{SERVER}}'");

```

but encoded never seems to get defined. In the Params section I put  
filter {{encoded}}

What am I doing wrong?

---

<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:** [December 8, 2022, 6:00pm UTC](https://community.postman.com/t/uri-encoding-in-pre-req/41885/2 "2022-12-08T18:00:38Z")

</div>

You can’t use the handlebars method within the scripts (pre-request or tests tab) like you can in the params section.

If you want to retrieve a variable in a script you have to use a different method.

```auto
pm.environment.get("server")

```

> **[Using variables | Postman Learning Center](https://learning.postman.com/docs/sending-requests/variables/)**
>
> Using variables: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.
