# How do I wrap an IP address before passing it along?

**URL:** <https://community.postman.com/t/how-do-i-wrap-an-ip-address-before-passing-it-along/5423>\
**Category:** Help Hub\
**Created:** [May 14, 2019, 12:22pm UTC](https://community.postman.com/t/how-do-i-wrap-an-ip-address-before-passing-it-along/5423 "2019-05-14T12:22:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![floripare](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/floripare/32/1836_2.png) [@floripare](https://community.postman.com/u/floripare)\
**Post date:** [May 14, 2019, 12:22pm UTC](https://community.postman.com/t/how-do-i-wrap-an-ip-address-before-passing-it-along/5423/1 "2019-05-14T12:22:53Z")

</div>

Hi guys,

This is my first post here, and I must start by saying I’m not a developer. Even the depth of my copy & paste JavaScript knowledge is rather shallow, so please be understanding.

I am very excited with Postman, as it allows me to get things done that on UI would either be too slow, or unreliable.

I’m trying to pass along an IP address that I get from one API to another.

I get the IP address as a pure text, the response would be:

`xxxx:xxxx:xxxx:xxxx...`

No quotation marks.

What I’ve been trying to do:

Pass that IP along to a Global Variable `{{ipv6}}` in a Pre-Script, then send this variable along with other info in a request to another API. I currently have:

```
pm.globals.set("ipv6", Object.values(response.json()));

```

Because it’s actually an IPv6, I always get the following error:

`Unexpected token ':' at 1:5`

I guess I need to somehow wrap the IPv6 address with quotation marks before I pass it on. I tried:

```
pm.globals.set("ipv6", "Object.values(response.json())");

```

But got the very same error message.

Thanks

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [May 14, 2019, 1:12pm UTC](https://community.postman.com/t/how-do-i-wrap-an-ip-address-before-passing-it-along/5423/2 "2019-05-14T13:12:14Z")

</div>

Hey @floripare,

Welcome to the community 👋

Are you able to provide an example of the response body (mask any sensitive data)? It will help us get you an answer quicker.

For example, if this was the response body:

```
{
    "ip": "xxxx:xxxx:xxxx:xxxx"
}

```

Added this to the `Tests` tab would set that value as a `Global` variable:

`pm.globals.set("ipv6", "pm.response.json().ip")`

More information about the `pm.*` API and the different options can be found here:

[https://learning.getpostman.com/docs/postman/scripts/postman\_sandbox\_api\_reference](https://learning.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference)

---

<div class="post-metadata">

**Author:** ![floripare](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/floripare/32/1836_2.png) [@floripare](https://community.postman.com/u/floripare)\
**Post date:** [May 14, 2019, 1:21pm UTC](https://community.postman.com/t/how-do-i-wrap-an-ip-address-before-passing-it-along/5423/3 "2019-05-14T13:21:14Z")

</div>

Hi @danny-dainton,

Thanks for your reply. I was actually using an API that had a response body just like the one you gave as an example. However, there seems to be an issue that is making Postman not receive IPv6, but instead an IPv4. I’ve contacted support about this and they referenced an ongoing issue that is being dealt with.

The API that I’m currently trying to use instead is

[https://ipv6bot.whatismyipaddress.com](https://ipv6bot.whatismyipaddress.com)

It returns the correct IPv6, but in plain text, not formatted as JSON:

![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/3/03aa6a98b6f0ce7ee7f807ae19530f9433be75bf.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [May 14, 2019, 1:28pm UTC](https://community.postman.com/t/how-do-i-wrap-an-ip-address-before-passing-it-along/5423/4 "2019-05-14T13:28:28Z")

</div>

That’s fine, you _could_ still use that to grab the value.

`pm.globals.set('ip_address', pm.response.text())`

 ![54](https://us1.discourse-cdn.com/getpostman/original/3X/3/c/3c7774ccd2ad4d207c7fdb44afbc2179aa7b8148.png)

---

<div class="post-metadata">

**Author:** ![floripare](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/floripare/32/1836_2.png) [@floripare](https://community.postman.com/u/floripare)\
**Post date:** [May 14, 2019, 1:55pm UTC](https://community.postman.com/t/how-do-i-wrap-an-ip-address-before-passing-it-along/5423/5 "2019-05-14T13:55:42Z")

</div>

This does work as a Test, but not as a Pre-request script.

```
pm.sendRequest("https://ipv6bot.whatismyipaddress.com", function (err, response) {
    console.log(response.json())
});
pm.globals.set("my-current-ipv6", pm.response.text());

```

I’ve tried to insert the pm.globals.set() command in the pm.sendRequest() function, but either way I get the same error:

![response-body-error](https://us1.discourse-cdn.com/getpostman/original/3X/2/0/20bd700482bfecf23421e7f18824aa4321b677bd.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [May 14, 2019, 2:07pm UTC](https://community.postman.com/t/how-do-i-wrap-an-ip-address-before-passing-it-along/5423/6 "2019-05-14T14:07:34Z")

</div>

This works in a slightly different way when used with the `pm.sendRequest()` function.

You need to do a couple of things, bring the `pm.globals` into the function and drop the `pm.` from the value. This will then use the `response` argument in the function.

```
pm.sendRequest("https://ipv6bot.whatismyipaddress.com", function (err, response) {
    pm.globals.set("my-current-ipv6", response.text());
});

```

Using `pm.globals.set("my-current-ipv6", pm.response.text());` in a `pre-request` will fail, this runs _before_ the requests so it doesn’t know what `pm.response` is, in that context.

Hope that makes sense 🙂

---

<div class="post-metadata">

**Author:** ![floripare](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/floripare/32/1836_2.png) [@floripare](https://community.postman.com/u/floripare)\
**Post date:** [May 14, 2019, 2:21pm UTC](https://community.postman.com/t/how-do-i-wrap-an-ip-address-before-passing-it-along/5423/7 "2019-05-14T14:21:07Z")

</div>

> [@danny-dainton](#):
>
> Hope that makes sense 🙂

Certain things never make sense to me 😊

Anyway, that worked! Thank you very much.

I had actually tried exactly this (bringing the `pm.globals` into the function and dropping the `pm.`, but I was adding the `pm.globals.set()` line _after_ the `console.log()`, not _instead of_ it.
