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:
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
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.
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.