Reputation: 41
Postman extension had a feature of setting an environment variable from one of the values from response headers or body. It is missing after update. Can someone help here.
Upvotes: 4
Views: 5291
Reputation: 1060
This is an old question, I'll leave this here as an update:
to set a variable from response body ( JSON ):
var jsonData = JSON.parse(responseBody);
pm.environement.set("your_var", jsonData["the_value"]);
and to get it from a header:
var value = pm.response.headers.get("the_header");
pm.environement.set("your_var", value);
Upvotes: 1
Reputation: 1742
You can set the environment variable from response body/header as follows:
From Response Body:
var body = JSON.parse(responseBody);
postman.setEnvironmentVariable("[environmentVariable]", body.variableName);
From Response Header:
var headerName = responseHeaders.headerName;
postman.setEnvironmentVariable("[environmentVariable]", headerName);
Upvotes: 8
Reputation: 2721
For Postman extension on Chrome latest version (by posting time) version 4.8.3 here.
Everthing is working fine regarding setting an environment variable programatically in either Pre-request script
section or Tests
section.
For more info, check docs here.
Upvotes: 3